]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
sqlite_backup.pl: Create backup of DB using locks to avoid problems with queuerunner.
authorBirin Sanchez <birin.sanchez@citrix.com>
Mon, 19 May 2014 08:46:50 +0000 (09:46 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 19 May 2014 10:47:39 +0000 (11:47 +0100)
ijc: Added to Makefile

Makefile
config/emesinae.conf
config/examples/test/emesinae.conf
scripts/sqlite_backup.pl [new file with mode: 0755]

index 7c484f4e5ad0478296e06e52c0fce82ac2d5f180..3b0feceb7ebc497c56a5d4f359420ac454a2f501 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,8 @@ SCRIPTS     := scripts/receive.pl     \
                scripts/queuerunner.pl \
                scripts/control.pl     \
                scripts/sendmail.pl    \
-               scripts/insertmail.pl
+               scripts/insertmail.pl  \
+               scripts/sqlite_backup.pl
 
 MODULES     := Emesinae/Bug.pm          \
                Emesinae/Common.pm       \
index 0aa1b3ffc5962d24b1f045dcfffeded7ab2ebd69..dd58c9425cd18501cefae0f7eda82a7c471a521d 100644 (file)
@@ -76,3 +76,6 @@ $c{ControlBlacklistPath} = "/etc/emesinae/control.blacklist";
 # Severity levels, in decending order of criticality
 @{ $c{SeverityLevels} } = qw/blocker critical normal wishlist/;
 $c{DefaultSeverity} = "normal";
+
+# Backup configuration
+$c{BackupDir}   = "/var/backups/";
index 528dcb6ca2cd521848580d16a67ca9812ff188be..11e4fadc8d6b9a2b68d78b89a6a9dd5efa8a3d2a 100644 (file)
@@ -70,3 +70,6 @@ $c{ControlBlacklistPath} = "/srv/test/etc/control.blacklist";
 # Severity levels, in decending order of criticality
 @{ $c{SeverityLevels} } = qw/blocker critical normal wishlist/;
 $c{DefaultSeverity} = "normal";
+
+# Backup configuration
+$c{BackupDir}   = "/srv/test/var/backups/";
diff --git a/scripts/sqlite_backup.pl b/scripts/sqlite_backup.pl
new file mode 100755 (executable)
index 0000000..557bc59
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+#
+# Creates a backup of the current DB in $c{BackupDir}
+# using locks to avoid race conditions with queuerunner
+
+use strict;
+use warnings;
+
+use Emesinae::Common;
+use Emesinae::Paths;
+use File::Copy;
+use File::Basename;
+
+readconfig();
+
+chdir( $c{BackupDir} ) || die("chdir to dir $c{BackupDir}: $!");
+
+
+my $lock = subsyslock('queuerunner');
+
+my $BackupDB = $c{BackupDir} . basename($c{DB});
+my $BackupDBxz = $c{BackupDir} . basename($c{DB}) . ".xz";
+my $OldBackupDBxz = $c{BackupDir} . basename($c{DB}) . ".old.xz";
+
+if ( -f $BackupDBxz ) {
+    move($BackupDBxz, $OldBackupDBxz) or die ("move failed: $!");
+}
+
+my $dbh = DBI->connect("dbi:SQLite:dbname=$c{DB}","","");
+$dbh->sqlite_backup_to_file( $BackupDB );
+undef $dbh;
+
+my @args = ("xz", "$BackupDB");
+system(@args) == 0
+    or die ("xz compress failed: $?");
+
+subsysunlock($lock);
+
+exit(0)