Added CLI ftp options to ADMIN_backup.pl script, Issue #442

git-svn-id: svn://192.168.202.10@2606 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2016-10-30 12:57:27 +00:00
parent 4dae168d35
commit a7840fbc02
+87 -47
View File
@@ -23,6 +23,7 @@
# 151006-1337 - Added archive_path flag, issue #896
# 160510-2249 - Added --db-without-archives flag, issue #945
# 160719-1415 - Added --dbs-selected=XXX---YYY option
# 161030-0847 - Added CLI ftp options, Issue #442
#
$secT = time();
@@ -40,6 +41,54 @@ $now_date = "$year-$mon-$mday $hour:$min:$sec";
$VDL_date = "$year-$mon-$mday 00:00:01";
$db_raw_files_copy=0;
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) )
{$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) )
{$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) )
{$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) )
{$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_dir/) && ($CLIREPORT_dir < 1) )
{$VARREPORT_dir = $line; $VARREPORT_dir =~ s/.*=//gi;}
$i++;
}
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
@@ -68,7 +117,11 @@ if (length($ARGV[0])>1)
print " [--without-sounds] = do not backup asterisk sounds\n";
print " [--without-voicemail] = do not backup asterisk voicemail\n";
print " [--without-crontab] = do not backup crontab\n";
print " [--ftp-transfer] = Transfer backup to FTP server\n";
print " [--ftp-transfer] = Transfer backup to the 'REPORTS' FTP server\n";
print " [--ftp-server=XXXXXXXX] = OVERRIDE FTP server to send file to\n";
print " [--ftp-login=XXXXXXXX] = OVERRIDE FTP user\n";
print " [--ftp-pass=XXXXXXXX] = OVERRIDE FTP pass\n";
print " [--ftp-dir=XXXXXXXX] = OVERRIDE remote FTP server directory to post files to\n";
print " [--debugX] = super debug\n";
print " [--debug] = debug\n";
print " [--test] = test\n";
@@ -174,6 +227,38 @@ if (length($ARGV[0])>1)
$ARCHIVEpath =~ s/ .*$//gi;
print "\n----- Archive path set to $ARCHIVEpath -----\n\n";
}
if ($args =~ /--ftp-server=/i)
{
@data_in = split(/--ftp-server=/,$args);
$VARREPORT_host = $data_in[1];
$VARREPORT_host =~ s/ .*//gi;
$VARREPORT_host =~ s/:/,/gi;
if ($DB > 0) {print "\n----- FTP SERVER: $VARREPORT_host -----\n\n";}
}
if ($args =~ /--ftp-login=/i)
{
@data_in = split(/--ftp-login=/,$args);
$VARREPORT_user = $data_in[1];
$VARREPORT_user =~ s/ .*//gi;
$VARREPORT_user =~ s/:/,/gi;
if ($DB > 0) {print "\n----- FTP LOGIN: $VARREPORT_user -----\n\n";}
}
if ($args =~ /--ftp-pass=/i)
{
@data_in = split(/--ftp-pass=/,$args);
$VARREPORT_pass = $data_in[1];
$VARREPORT_pass =~ s/ .*//gi;
$VARREPORT_pass =~ s/:/,/gi;
if ($DB > 0) {print "\n----- FTP PASS: <SET> -----\n\n";}
}
if ($args =~ /--ftp-dir=/i)
{
@data_in = split(/--ftp-dir=/,$args);
$VARREPORT_dir = $data_in[1];
$VARREPORT_dir =~ s/ .*//gi;
$VARREPORT_dir =~ s/:/,/gi;
if ($DB > 0) {print "\n----- FTP DIR: $VARREPORT_dir -----\n\n";}
}
}
}
else
@@ -181,52 +266,6 @@ else
print "no command line options set\n";
}
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_host/) && ($CLIREPORT_host < 1) )
{$VARREPORT_host = $line; $VARREPORT_host =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_user/) && ($CLIREPORT_user < 1) )
{$VARREPORT_user = $line; $VARREPORT_user =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_pass/) && ($CLIREPORT_pass < 1) )
{$VARREPORT_pass = $line; $VARREPORT_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_port/) && ($CLIREPORT_port < 1) )
{$VARREPORT_port = $line; $VARREPORT_port =~ s/.*=//gi;}
if ( ($line =~ /^VARREPORT_dir/) && ($CLIREPORT_dir < 1) )
{$VARREPORT_dir = $line; $VARREPORT_dir =~ s/.*=//gi;}
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
@@ -542,6 +581,7 @@ if ($DBX) {print "rm -fR $ARCHIVEpath/temp\n";}
#### FTP to the Backup server and upload the final file
if ($ftp_transfer > 0)
{
if ($DBX) {print "Starting FTP transfer...($VARREPORT_user at $VARREPORT_host dir: $VARREPORT_dir)\n";}
use Net::FTP;
$ftp = Net::FTP->new("$VARREPORT_host", Port => "$VARREPORT_port", Debug => "$FTPdebug");
$ftp->login("$VARREPORT_user","$VARREPORT_pass");