aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/SQLite/dbCore.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2017-05-13 14:18:28 +0200
committerDarkelarious <darkelarious@333networks.com>2017-05-13 14:20:49 +0200
commit34a2c7390ea9662d33258d384e72fff1912343ff (patch)
treed96ea33c0107e4906a152aa1de4b5c75b81ba0a8 /lib/MasterServer/Database/SQLite/dbCore.pm
parent84af66aba26d2088d5d95c240d176f3edaf17b58 (diff)
downloadMasterServer-Perl-34a2c7390ea9662d33258d384e72fff1912343ff.tar.gz
MasterServer-Perl-34a2c7390ea9662d33258d384e72fff1912343ff.zip
revised synchronization methods, config settings and bug fixesv2.3.0
Diffstat (limited to 'lib/MasterServer/Database/SQLite/dbCore.pm')
-rwxr-xr-xlib/MasterServer/Database/SQLite/dbCore.pm38
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/MasterServer/Database/SQLite/dbCore.pm b/lib/MasterServer/Database/SQLite/dbCore.pm
index f58d535..0772a4e 100755
--- a/lib/MasterServer/Database/SQLite/dbCore.pm
+++ b/lib/MasterServer/Database/SQLite/dbCore.pm
@@ -1,11 +1,11 @@
-
package MasterServer::Database::SQLite::dbCore;
use strict;
use warnings;
+use POSIX qw/strftime/;
use Exporter 'import';
-our @EXPORT = qw| database_login |;
+our @EXPORT = qw| database_login dump_database |;
################################################################################
## login to the database with credentials provided in the config file.
@@ -19,7 +19,10 @@ sub database_login {
# get db info
my @db_type = split(':', $self->{dblogin}->[0]);
-
+
+ # inform what db we try to load
+ $self->log("info","Database: $db_type[1], $db_type[2]");
+
# check if database file exists
my $db_file = [split(':', $self->{dblogin}->[0])]->[2];
$db_file =~ s/dbname=//i;
@@ -31,10 +34,7 @@ sub database_login {
# end program
$self->halt();
}
-
- # inform what DB we try to load
- # $self->log("info","Database: $db_type[1]");
-
+
# create the dbi object
my $dbh = DBI->connect(@{$self->{dblogin}}, {PrintError => 1});
@@ -72,4 +72,28 @@ sub database_login {
return undef;
}
+################################################################################
+## Dump the database in the data/dump folder.
+## useful for backups, historical data
+################################################################################
+sub dump_database {
+ my $self = shift;
+
+ # filename / time
+ my $time = strftime('%Y-%m-%d-%H-%M',localtime);
+
+ # read db credentials from db login
+ my @db_type = split ':', $self->{dblogin}->[0];
+ $db_type[2] =~ s/dbname=//;
+
+ # split db path
+ my @db_path = split '/', $db_type[2];
+
+ # use pg_dump to dump Postgresql databases
+ system("cp $db_type[2] $self->{root}/data/dumps/SQLite-$time-$db_path[-1]");
+
+ # log
+ $self->log("dump", "Dumping database to /data/dumps/SQLite-$time-$db_path[-1]");
+}
+
1;