diff options
| author | Darkelarious <darkelarious@333networks.com> | 2017-05-13 14:18:28 +0200 |
|---|---|---|
| committer | Darkelarious <darkelarious@333networks.com> | 2017-05-13 14:20:49 +0200 |
| commit | 34a2c7390ea9662d33258d384e72fff1912343ff (patch) | |
| tree | d96ea33c0107e4906a152aa1de4b5c75b81ba0a8 /lib/MasterServer/Database/Pg/dbCore.pm | |
| parent | 84af66aba26d2088d5d95c240d176f3edaf17b58 (diff) | |
| download | MasterServer-Perl-2e83b2e08d7209b8173e4d16972130beaa8c5cd1.tar.gz MasterServer-Perl-2e83b2e08d7209b8173e4d16972130beaa8c5cd1.zip | |
revised synchronization methods, config settings and bug fixesv2.3.0
Diffstat (limited to 'lib/MasterServer/Database/Pg/dbCore.pm')
| -rwxr-xr-x | lib/MasterServer/Database/Pg/dbCore.pm | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/MasterServer/Database/Pg/dbCore.pm b/lib/MasterServer/Database/Pg/dbCore.pm index 90899f7..0891012 100755 --- a/lib/MasterServer/Database/Pg/dbCore.pm +++ b/lib/MasterServer/Database/Pg/dbCore.pm @@ -1,11 +1,11 @@ - package MasterServer::Database::Pg::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,6 +19,9 @@ 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]"); # create the dbi object my $dbh = DBI->connect(@{$self->{dblogin}}, {PrintError => 1}); @@ -47,4 +50,30 @@ 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); + + # FIXME + # separate absolute path and relative path, + # split database filename for dump filename. + + # read db credentials from db login + my @db_type = split(':', $self->{dblogin}->[0]); + $db_type[2] =~ s/dbname=//; + + # use pg_dump to dump Postgresql databases + system("pg_dump $db_type[2] -U $self->{dblogin}->[1] > $self->{root}/data/dumps/Pg-$time-$db_type[2].db"); + + # log + $self->log("dump", "Dumping database to /data/dumps/$db_type[1]-$time.db"); +} + + 1; |
