Script-for-probes-backup: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<?php $silence=false; $today=date("Y-m-d"); $backupfolder="/home/voipmonitor/backup-config/$today"; exec("mysql -h MYSQLIP -u MYSQLUSER -pPASSWORD -e 'select id_sensor...") |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<?php | <?php | ||
$silence=false; | |||
$today=date("Y-m-d"); | |||
$backupfolder="/home/voipmonitor/backup-config/$today"; | |||
exec("mysql -h MYSQLIP -u MYSQLUSER -pPASSWORD -e 'select id_sensor,host from voipmonitor.sensors\G'",$out,$rc); | |||
if($rc) $notify[]="No connection to DB"; | if($rc) $notify[]="No connection to DB"; | ||
$notify=false; | $notify=false; | ||
$sensors=array(); | $sensors=array(); | ||
#get id_sensor as a key, host,port into subfield - dirtyway | #get id_sensor as a key, host,port into subfield - dirtyway | ||
foreach ($out as $key => $line) { | foreach ($out as $key => $line) { | ||
if ($line[0]=="*") continue; | |||
if (strpos($line,"id_sensor") === FALSE) continue; | |||
$tempid=explode (":",$line,2); | |||
$temphost=explode (":",$out[$key+1],2); | |||
$sensors[trim($tempid[1])]['host']=trim($temphost[1]); | |||
} | } | ||
#get config from each host using ssh | #get config from each host using ssh | ||
foreach ($sensors as $id=>$sensor) { | foreach ($sensors as $id=>$sensor) { | ||
$destdir="$backupfolder/$id"; | |||
if (!file_exists($destdir)) mkdir($destdir, 0777, true); | |||
exec("scp voipmonitor@".$sensor['host']."://etc/voipmonitor.conf $destdir",$out,$rc); | |||
if($rc) $notify[]='Cannot ssh to'.$sensor['host']; | |||
} | } | ||
#backup database tables | #backup database tables | ||
$destdir="$backupfolder/mysql-config"; | $destdir="$backupfolder/mysql-config"; | ||
if (!file_exists($destdir)) mkdir($destdir, 0777, true); | if (!file_exists($destdir)) mkdir($destdir, 0777, true); | ||
exec ("php /var/www/html/php/run.php backupGuiTables -t config -f $destdir/backup.zip",$out,$rc) | exec ("php /var/www/html/php/run.php backupGuiTables -t config -f $destdir/backup.zip",$out,$rc); | ||
if($rc) $notify[]='Cannot backup mysql config tables'; | if($rc) $notify[]='Cannot backup mysql config tables'; | ||
#If silence not set print errors | #If silence not set print errors | ||
if($notify&&!$silence) print_r($notify); | if($notify&&!$silence) print_r($notify); | ||
?> | |||
?> |
Latest revision as of 10:27, 9 March 2021
<?php $silence=false; $today=date("Y-m-d"); $backupfolder="/home/voipmonitor/backup-config/$today"; exec("mysql -h MYSQLIP -u MYSQLUSER -pPASSWORD -e 'select id_sensor,host from voipmonitor.sensors\G'",$out,$rc); if($rc) $notify[]="No connection to DB"; $notify=false; $sensors=array(); #get id_sensor as a key, host,port into subfield - dirtyway foreach ($out as $key => $line) { if ($line[0]=="*") continue; if (strpos($line,"id_sensor") === FALSE) continue; $tempid=explode (":",$line,2); $temphost=explode (":",$out[$key+1],2); $sensors[trim($tempid[1])]['host']=trim($temphost[1]); } #get config from each host using ssh foreach ($sensors as $id=>$sensor) { $destdir="$backupfolder/$id"; if (!file_exists($destdir)) mkdir($destdir, 0777, true); exec("scp voipmonitor@".$sensor['host']."://etc/voipmonitor.conf $destdir",$out,$rc); if($rc) $notify[]='Cannot ssh to'.$sensor['host']; } #backup database tables $destdir="$backupfolder/mysql-config"; if (!file_exists($destdir)) mkdir($destdir, 0777, true); exec ("php /var/www/html/php/run.php backupGuiTables -t config -f $destdir/backup.zip",$out,$rc); if($rc) $notify[]='Cannot backup mysql config tables'; #If silence not set print errors if($notify&&!$silence) print_r($notify); ?>