[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5144] branches/1.3



Revision: 5144
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5144&view=rev
Author:   hasorli
Date:     2012-10-05 23:27:55 +0000 (Fri, 05 Oct 2012)
Log Message:
-----------
Add patch fix "Backup does not test for failure" from Nick Prater (3574876)

Modified Paths:
--------------
    branches/1.3/LedgerSMB/Database.pm
    branches/1.3/scripts/setup.pl

Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm	2012-10-05 21:29:07 UTC (rev 5143)
+++ branches/1.3/LedgerSMB/Database.pm	2012-10-05 23:27:55 UTC (rev 5144)
@@ -89,6 +89,9 @@
 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 {
@@ -109,8 +112,13 @@
     my $backupfile = $LedgerSMB::Sysconfig::backuppath .
                      "/roles_${date}.sql";
 
-    system("pg_dumpall -r -f $backupfile");
+    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");
+    }
+
     $ENV{PGUSER} = $old_pguser;
     $ENV{PGPASSWORD} = $old_pgpass;
 
@@ -128,6 +136,9 @@
 The resulting file is named backup_[dbname]_[date].bak with the date in
 yyyy-mm-dd format.
 
+It returns the full path of the resulting backup file on success, or undef on 
+failure.
+
 =cut
 
 sub db_backup {
@@ -148,8 +159,13 @@
     my $backupfile = $LedgerSMB::Sysconfig::backuppath .
                      "/backup_$self->{company_name}_${date}.bak";
 
-    system("pg_dump  -F c -f '$backupfile' '$self->{company_name}'");
+    my $exit_code = system("pg_dump  -F c -f '$backupfile' '$self->{company_name}'");
 
+    if($exit_code != 0) {
+        $backupfile = undef;
+        $logger->error("backup failed: non-zero exit code from pg_dump");
+    }
+
     $ENV{PGUSER} = $old_pguser;
     $ENV{PGPASSWORD} = $old_pgpass;
 

Modified: branches/1.3/scripts/setup.pl
===================================================================
--- branches/1.3/scripts/setup.pl	2012-10-05 21:29:07 UTC (rev 5143)
+++ branches/1.3/scripts/setup.pl	2012-10-05 23:27:55 UTC (rev 5144)
@@ -223,6 +223,8 @@
         $request->error($request->{_locale}->text('Invalid backup request'));
     }
 
+    $backupfile or $request->error($request->{_locale}->text('Error creating backup file'));
+
     if ($request->{backup_type} eq 'email'){
         my $csettings = $LedgerSMB::Company_Config::settings;
 	my $mail = new LedgerSMB::Mailer(

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.