1 package FS::Cron::backup;
4 use vars qw( @ISA @EXPORT_OK );
8 use FS::UID qw(driver_name datasrc);
10 @ISA = qw( Exporter );
11 @EXPORT_OK = qw( backup );
14 my $conf = new FS::Conf;
15 my $localdest = $conf->config('dump-localdest');
16 my $scpdest = $conf->config('dump-scpdest');
17 return unless $localdest || $scpdest;
19 my $filename = time2str('%Y%m%d%H%M%S',time);
21 datasrc =~ /dbname=([\w\.]+)$/ or die "unparsable datasrc ". datasrc;
25 if ( driver_name eq 'Pg' ) {
26 system("pg_dump -Fc $database >/var/tmp/$database.Pg");
28 } elsif ( driver_name eq 'mysql' ) {
29 system("mysqldump $database >/var/tmp/$database.sql");
32 die "database dumps not yet supported for ". driver_name;
34 chmod 0600, "/var/tmp/$database.$ext";
36 if ( $conf->config('dump-pgpid') ) {
40 $gpg->encrypt( plaintext => "/var/tmp/$database.$ext",
41 output => "/var/tmp/$database.gpg",
42 recipient => $conf->config('dump-pgpid'),
44 unlink "/var/tmp/$database.$ext" or die $!;
45 chmod 0600, "/var/tmp/$database.gpg";
50 copy("/var/tmp/$database.$ext", "$localdest/$filename.$ext") or die $!;
51 chmod 0600, "$localdest/$filename.$ext";
55 eval "use Net::SCP qw(scp);";
57 scp("/var/tmp/$database.$ext", "$scpdest/$filename.$ext");
60 unlink "/var/tmp/$database.$ext" or die $!;