Added did only option to recording export script
Added settings-only option to backup script, and removed log export from no-log option git-svn-id: svn://192.168.202.10@2177 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# ADMIN_backup.pl version 2.4
|
||||
# ADMIN_backup.pl version 2.10
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# Backs-up the asterisk database, conf/agi/sounds/bin files
|
||||
#
|
||||
# Copyright (C) 2010 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
# Copyright (C) 2014 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
|
||||
#
|
||||
# CHANGELOG
|
||||
#
|
||||
@@ -17,6 +17,7 @@
|
||||
# 100211-0910 - Added crontab backup and voicemail backup option
|
||||
# 100817-1202 - Fixed test option bug
|
||||
# 101208-0452 - Added checks for zaptel and dahdi conf files
|
||||
# 141103-1505 - Added option to export without leads, logs, servers or phones
|
||||
#
|
||||
|
||||
$secT = time();
|
||||
@@ -47,6 +48,7 @@ if (length($ARGV[0])>1)
|
||||
{
|
||||
print "allowed run time options:\n";
|
||||
print " [--db-only] = only backup the database\n";
|
||||
print " [--db-settings-only] = only backup the database without leads, logs, servers or phones\n";
|
||||
print " [--db-without-logs] = do not backup the log tables in the database\n";
|
||||
print " [--conf-only] = only backup the asterisk conf files\n";
|
||||
print " [--without-db] = do not backup the database\n";
|
||||
@@ -78,6 +80,11 @@ if (length($ARGV[0])>1)
|
||||
$T=1; $TEST=1;
|
||||
print "\n-----TESTING -----\n\n";
|
||||
}
|
||||
if ($args =~ /--db-settings-only/i)
|
||||
{
|
||||
$db_settings_only=1;
|
||||
print "\n----- Backup Database Settings Only -----\n\n";
|
||||
}
|
||||
if ($args =~ /--db-only/i)
|
||||
{
|
||||
$db_only=1;
|
||||
@@ -289,14 +296,54 @@ if ( ($without_db < 1) && ($conf_only < 1) )
|
||||
$dump_non_log_command = "$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs $VARDB_database $archive_tables | $gzipbin > $ARCHIVEpath/temp/$VARserver_ip$VARDB_database$wday.gz";
|
||||
$dump_log_command = "$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs --no-data --no-create-db $VARDB_database $log_tables | $gzipbin > $ARCHIVEpath/temp/LOGS_$VARserver_ip$VARDB_database$wday.gz";
|
||||
|
||||
if ($DBX) {print "$dump_non_log_command\n$dump_log_command";}
|
||||
if ($DBX) {print "$dump_non_log_command\nDEBUG: LOG EXPORT COMMAND(not run): $dump_log_command\n";}
|
||||
`$dump_non_log_command`;
|
||||
`$dump_log_command`;
|
||||
# `$dump_log_command`;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($DBX) {print "$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs $VARDB_database | $gzipbin > $ARCHIVEpath/temp/$VARserver_ip$VARDB_database$wday.gz\n";}
|
||||
`$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs $VARDB_database | $gzipbin > $ARCHIVEpath/temp/$VARserver_ip$VARDB_database$wday.gz`;
|
||||
if ($db_settings_only)
|
||||
{
|
||||
use DBI;
|
||||
|
||||
### connect to MySQL database defined in the conf file
|
||||
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
|
||||
or die "Couldn't connect to database: " . DBI->errstr;
|
||||
|
||||
$stmtA = "show tables;";
|
||||
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||
$sthArows=$sthA->rows;
|
||||
$rec_count=0;
|
||||
$log_tables='';
|
||||
$archive_tables='';
|
||||
while ($sthArows > $rec_count)
|
||||
{
|
||||
@aryA = $sthA->fetchrow_array;
|
||||
if ($aryA[0] =~ /_log|server_performance|vicidial_ivr|vicidial_hopper|vicidial_manager|web_client_sessions|imm_outcomes|server|^phones|stats|vicidial_list$/)
|
||||
{
|
||||
$log_tables .= " $aryA[0]";
|
||||
}
|
||||
else
|
||||
{
|
||||
$archive_tables .= " $aryA[0]";
|
||||
}
|
||||
$rec_count++;
|
||||
}
|
||||
$sthA->finish();
|
||||
|
||||
$dump_non_log_command = "$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs $VARDB_database $archive_tables | $gzipbin > $ARCHIVEpath/temp/SETTINGSONLY_$VARserver_ip$VARDB_database$wday.gz";
|
||||
$dump_log_command = "$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs --no-data --no-create-db $VARDB_database $log_tables | $gzipbin > $ARCHIVEpath/temp/LOGS_$VARserver_ip$VARDB_database$wday.gz";
|
||||
|
||||
if ($DBX) {print "$dump_non_log_command\nNOT ARCHIVED: $dump_log_command\n";}
|
||||
`$dump_non_log_command`;
|
||||
# `$dump_log_command`;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($DBX) {print "$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs $VARDB_database | $gzipbin > $ARCHIVEpath/temp/$VARserver_ip$VARDB_database$wday.gz\n";}
|
||||
`$mysqldumpbin --user=$VARDB_user --password=$VARDB_pass --lock-tables --flush-logs $VARDB_database | $gzipbin > $ARCHIVEpath/temp/$VARserver_ip$VARDB_database$wday.gz`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,6 +453,13 @@ if ($ftp_transfer > 0)
|
||||
}
|
||||
|
||||
|
||||
### calculate time to run script ###
|
||||
$secY = time();
|
||||
$secZ = ($secY - $secX);
|
||||
$secZm = ($secZ /60);
|
||||
|
||||
if (!$Q) {print "script execution time in seconds: $secZ minutes: $secZm\n";}
|
||||
|
||||
if ($DBX) {print "DONE, Exiting...\n";}
|
||||
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user