#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } use MIME::Lite; use Mail::Sendmail; use Date::Calc qw(:all); #------------------------------------------------------------------------------- our $debug = $ARGV[0] ; our $username = $ARGV[1] ; # perl /usr/lib/cgi-bin/scripts/cron/email_sql_backup.pl 1 rory #------------------------------------------------------------------------------------------ &config_set_paths; &config_set_vars ; &today; &read_bz2_backups($mysqlbakpath,'bz2'); &sort_files; exit ; #------------------------------------------------------------------------------- sub read_bz2_backups { my ($path,$ext) = @_; opendir BP_DIR,"$path" or die "Cannot open $path: $!\n"; my @backups = grep { /\.$ext$/ } readdir BP_DIR; closedir BP_DIR; for (@backups) { my ($db_bk_name,$db_bk_date,$db_bk_time,$db_bk_ext) = split(/\./); $db_bk_date =~ s/\-//g; push @bkfiles, "$db_bk_date$db_bk_time|$_" ; } } #------------------------------------------------------------------------------- sub sort_files { my @sorted_bkfiles = sort {$b <=> $a} @bkfiles ; my ($sortprefix,$file) = split(/\|/, shift @sorted_bkfiles); if ($file) { &send_email($file); } } #------------------------------------------------------------------------------- sub send_email { my ($attachname) = @_ ; my $to = ($debug) ? $email_it_1 : $email_accounts ; my $bcc = ($debug) ? '' : $email_it_1 ; &common_send_smtp_mail('',$to,'',$bcc,"$useropts{acronym} MySQL Backup : $attachname",'Please see DB backup attached...'," $attachname ",'html'," MySQL latest Backup ",$mysqlbakpath,$attachname,'','','') ; # $msg = MIME::Lite -> new( # From => "$useropts{acronym} ", # To => $to, # Subject => "$useropts{acronym} MySQL Backup : $attachname", # Type => 'multipart/mixed' # ); # # my $boundary = "====" . time() . "===="; # my $email_body = < # # # # # # # #
# ITV #

# # # # # #
 MySQL latest Backup 
 $attachname 
#

#
# # # END_OF_BODY # $msg -> attach( # Type => 'text/html', # Data => $email_body # ); # $msg -> attach ( # Type => 'AUTO', # Path => "$mysqlbakpath/$attachname", # Filename => "$attachname", # Disposition => 'attachment' # ) or die "Error adding $path : $attach $!\n"; # $msg -> send ('smtp','localhost', Debug=>0 ); } #------------------------------------------------------------------------------- use common ; use today ; use uploader ; use cfg_paths ; 1;