X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-daily;h=1db786120e4368c250baa3efb51906ddfdd9b1a9;hb=1583472a6afefb1ad33e05656fd206674f37d9df;hp=22bf2c96396e0c67a3de6ca0dc8c5d8f631a74a8;hpb=0f5ad6c181cccbbdec6c48ea74e41d92ef5e3a26;p=freeside.git diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 22bf2c963..1db786120 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -4,8 +4,9 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup driver_name dbh); +use FS::UID qw(adminsuidsetup driver_name dbh datasrc); use FS::Record qw(qsearch qsearchs); +use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) @@ -30,7 +31,7 @@ foreach $cust_main ( @cust_main ) { # $^T not $time because -d is for pre-printing invoices foreach my $cust_pkg ( - grep { $_->expire && $_->expire >= $^T } $cust_main->ncancelled_pkgs + grep { $_->expire && $_->expire <= $^T } $cust_main->ncancelled_pkgs ) { my $error = $cust_pkg->cancel; warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". @@ -50,12 +51,29 @@ foreach $cust_main ( @cust_main ) { } if ( driver_name eq 'Pg' ) { + dbh->{AutoCommit} = 1; #so we can vacuum foreach my $statement ( 'vacuum', 'vacuum analyze' ) { my $sth = dbh->prepare($statement) or die dbh->errstr; $sth->execute or die $sth->errstr; } } +#local hack +my $conf = new FS::Conf; +my $dest = $conf->config('dump-scpdest'); +if ( $dest ) { + datasrc =~ /dbname=([\w\.]+)$/ or die "unparsable datasrc ". datasrc; + my $database = $1; + eval "use Net::SCP qw(scp);"; + if ( driver_name eq 'Pg' ) { + system("pg_dump $database >/var/tmp/$database.sql") + } else { + die "database dumps not yet supported for ". driver_name; + } + scp("/var/tmp/$database.sql", $dest); + unlink "/var/tmp/$database.sql" or die $!; +} + # subroutines sub untaint_argv {