diff --git a/LedgerSMB/Database.pm b/LedgerSMB/Database.pm index f48419d946..ab4b8f2b6b 100644 --- a/LedgerSMB/Database.pm +++ b/LedgerSMB/Database.pm @@ -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 diff --git a/LedgerSMB/Scripts/setup.pm b/LedgerSMB/Scripts/setup.pm index 9663531931..5bf4d2b2dc 100644 --- a/LedgerSMB/Scripts/setup.pm +++ b/LedgerSMB/Scripts/setup.pm @@ -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; diff --git a/Makefile.PL b/Makefile.PL index df571583d8..c173c9465f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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';