aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterServer/Database/Pg/dbCore.pm
diff options
context:
space:
mode:
authorDarkelarious <darkelarious@333networks.com>2017-08-22 11:00:13 +0200
committerDarkelarious <darkelarious@333networks.com>2017-08-22 11:00:13 +0200
commitc06322da38b4cb76b2036af1a5448083adb8ff20 (patch)
tree189c9f0fec3325be927f763aba23cf18aa68cfe4 /lib/MasterServer/Database/Pg/dbCore.pm
parente0d727670cbeda0db0812c5c9efc503d75f8d0a4 (diff)
downloadMasterServer-Perl-2.4.0.tar.gz
MasterServer-Perl-2.4.0.zip
new server checking mechanism, complete recode of major functionsv2.4.0
Diffstat (limited to 'lib/MasterServer/Database/Pg/dbCore.pm')
-rwxr-xr-xlib/MasterServer/Database/Pg/dbCore.pm38
1 files changed, 5 insertions, 33 deletions
diff --git a/lib/MasterServer/Database/Pg/dbCore.pm b/lib/MasterServer/Database/Pg/dbCore.pm
index 0891012..4b2d16f 100755
--- a/lib/MasterServer/Database/Pg/dbCore.pm
+++ b/lib/MasterServer/Database/Pg/dbCore.pm
@@ -4,50 +4,30 @@ use strict;
use warnings;
use POSIX qw/strftime/;
use Exporter 'import';
-
our @EXPORT = qw| database_login dump_database |;
################################################################################
## login to the database with credentials provided in the config file.
## returns dbh object or quits application on error.
-##
-## Recommended database types: Postgresql, MySQL or SQLite. Warranty void if
-## other database types are used. Use at your own risk.
################################################################################
sub database_login {
my $self = shift;
-
- # 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
+
+ # connect to Pg database
my $dbh = DBI->connect(@{$self->{dblogin}}, {PrintError => 1});
# verify that the database connected
if (defined $dbh) {
-
- # log the event
- $self->log("info","Connected to the $db_type[1] database.");
-
- # turn on error printing
+ $self->log("info","Connected to $db_type[1] database $db_type[2]");
$dbh->{printerror} = 1;
-
- # return the dbi object for further use
return $dbh;
}
else {
# fatal error
$self->log("fatal", "$DBI::errstr!");
-
- # end program
$self->halt();
}
-
- # in case of any other error, return undef.
- return undef;
}
################################################################################
@@ -56,23 +36,15 @@ sub database_login {
################################################################################
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");
+ $self->log("dump", "Dumping database to /data/dumps/Pg-$time-$db_type[2].db");
}