[freeside-commits] freeside/FS/FS/Cron backup.pm,1.4.2.1,1.4.2.2
Ivan,,,
ivan at wavetail.420.am
Mon Mar 28 17:32:23 PDT 2011
Update of /home/cvs/cvsroot/freeside/FS/FS/Cron
In directory wavetail.420.am:/tmp/cvs-serv12621/FS/FS/Cron
Modified Files:
Tag: FREESIDE_2_1_BRANCH
backup.pm
Log Message:
local backups, RT#12180
Index: backup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Cron/backup.pm,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -w -d -r1.4.2.1 -r1.4.2.2
--- backup.pm 10 Jan 2011 17:45:43 -0000 1.4.2.1
+++ backup.pm 29 Mar 2011 00:32:21 -0000 1.4.2.2
@@ -3,43 +3,62 @@
use strict;
use vars qw( @ISA @EXPORT_OK );
use Exporter;
+use File::Copy;
use Date::Format;
use FS::UID qw(driver_name datasrc);
@ISA = qw( Exporter );
- at EXPORT_OK = qw( backup_scp );
+ at EXPORT_OK = qw( backup );
-sub backup_scp {
+sub backup {
my $conf = new FS::Conf;
- my $dest = $conf->config('dump-scpdest');
- if ( $dest ) {
- $dest .= time2str('/%Y%m%d%H%M%S',time);
+ my $localdest = $conf->config('dump-localdest');
+ my $scpdest = $conf->config('dump-scpdest');
+ return unless $localdest || $scpdest;
+
+ my $filename = time2str('%Y%m%d%H%M%S',time);
+
datasrc =~ /dbname=([\w\.]+)$/ or die "unparsable datasrc ". datasrc;
my $database = $1;
- eval "use Net::SCP qw(scp);";
- die $@ if $@;
+
+ my $ext;
if ( driver_name eq 'Pg' ) {
- system("pg_dump -Fc $database >/var/tmp/$database.Pg")
+ system("pg_dump -Fc $database >/var/tmp/$database.Pg");
+ $ext = 'Pg';
+ } elsif ( driver_name eq 'mysql' ) {
+ system("mysqldump $database >/var/tmp/$database.sql");
+ $ext = 'sql';
} else {
die "database dumps not yet supported for ". driver_name;
}
+ chmod 0600, "/var/tmp/$database.$ext";
+
if ( $conf->config('dump-pgpid') ) {
eval 'use GnuPG;';
die $@ if $@;
my $gpg = new GnuPG;
- $gpg->encrypt( plaintext => "/var/tmp/$database.Pg",
+ $gpg->encrypt( plaintext => "/var/tmp/$database.$ext",
output => "/var/tmp/$database.gpg",
recipient => $conf->config('dump-pgpid'),
);
- chmod 0600, '/var/tmp/$database.gpg';
- scp("/var/tmp/$database.gpg", "$dest.gpg");
- unlink "/var/tmp/$database.gpg" or die $!;
- } else {
- chmod 0600, '/var/tmp/$database.Pg';
- scp("/var/tmp/$database.Pg", "$dest.Pg");
+ unlink "/var/tmp/$database.$ext" or die $!;
+ chmod 0600, "/var/tmp/$database.gpg";
+ $ext = 'gpg';
}
- unlink "/var/tmp/$database.Pg" or die $!;
+
+ if ( $localdest ) {
+ copy("/var/tmp/$database.$ext", "$localdest/$filename.$ext") or die $!;
+ chmod 0600, "$localdest/$filename.$ext";
+ }
+
+ if ( $scpdest ) {
+ eval "use Net::SCP qw(scp);";
+ die $@ if $@;
+ scp("/var/tmp/$database.$ext", "$scpdest/$filename.$ext");
}
+
+ unlink "/var/tmp/$database.$ext" or die $!;
+
}
1;
More information about the freeside-commits
mailing list