Skip to content

Commit

Permalink
moving server version checking to PGObject::Util::DBAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
einhverfr committed Sep 14, 2014
1 parent e5508c9 commit 7b72dd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 50 deletions.
48 changes: 0 additions & 48 deletions LedgerSMB/Database.pm
Expand Up @@ -58,54 +58,6 @@ sub loader_log_filename {
}


=head2 base_backup
This routine connects to the database using pg_dumpall and returns a plain text,
roles-only dump of the current database cluster. This is left uncompressed for
readability and ease of troubleshooting. Base backups are advised to be taken
frequently and in conjunction with single database backups. The single database
backups will backup all data but no roles. Restoring a new database onto a new
server post-crash with only the single-database backup thus means recreating all
users.
The file is named roles_[date].sql by default where the date is in
yyyy-mm-dd format.
It returns the full path of the resulting backup file on success, or undef on
failure.
=cut

sub base_backup {
my $self = shift @_;

local %ENV; # Make sure that - when leaving the scope - %ENV is restored
$ENV{PGUSER} = $self->{username};
$ENV{PGPASSWORD} = $self->{password};
$ENV{PGDATABASE} = $self->{company_name};
$ENV{PGHOST} = $LedgerSMB::Sysconfig::db_host;
$ENV{PGPORT} = $LedgerSMB::Sysconfig::db_port;

my @t = localtime(time);
$t[4]++;
$t[5] += 1900;
$t[3] = substr( "0$t[3]", -2 );
$t[4] = substr( "0$t[4]", -2 );
my $date = "$t[5]-$t[4]-$t[3]";

my $backupfile = $LedgerSMB::Sysconfig::backuppath .
"/roles_${date}.sql";

my $exit_code = system("pg_dumpall -r -f $backupfile");

if($exit_code != 0) {
$backupfile = undef;
$logger->error("backup failed: non-zero exit code from pg_dumpall");
}

return $backupfile;
}

=head2 get_info()
This routine connects to the database using DBI and attempts to determine if a
Expand Down
12 changes: 11 additions & 1 deletion LedgerSMB/Scripts/setup.pm
Expand Up @@ -292,7 +292,17 @@ sub run_backup {
my $mimetype;

if ($request->{backup} eq 'roles'){
$backupfile = $database->base_backup;
my @t = localtime(time);
$t[4]++;
$t[5] += 1900;
$t[3] = substr( "0$t[3]", -2 );
$t[4] = substr( "0$t[4]", -2 );
my $date = "$t[5]-$t[4]-$t[3]";

$backupfile = $database->backup_globals(
tempdir => $LedgerSMB::Sysconfig::backuppath,
file => "roles_${date}.sql"
);
$mimetype = 'text/x-sql';
} elsif ($request->{backup} eq 'db'){
$backupfile = $database->backup;
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -45,7 +45,7 @@ requires 'PGObject::Simple::Role';
requires 'PGObject::Type::BigFloat';
requires 'PGObject::Type::DateTime';
requires 'PGObject::Util::DBMethod';
requires 'PGObject::Util::DBAdmin' => '0.04';
requires 'PGObject::Util::DBAdmin' => '0.05';

recommends 'Math::BigInt::GMP';

Expand Down

0 comments on commit 7b72dd3

Please sign in to comment.