Difference between revisions of "Backup and restore GUI tables"

From VoIPmonitor.org
Jump to navigation Jump to search
(Created page with " #!/bin/bash #from where to get GUI's data primaryhost=10.112.5.77 #if backups should be kept locally keepbackups=true datestr=`date +'%Y%m%d-%H%M'` backupfilenamere...")
 
Line 1: Line 1:
 +
== Description =
 +
Here follows the script used for peridically restore of settings from proimary db(GUI) on a backup GUI(db) host. (can be used with migration instance to mirror also GUI settings not only calldata)
 +
 +
 +
== Requirements ==
 +
the script requires to set at least **primaryhost** variable, folders defined by backupfilenameremote and backupfilenamelocal needs to exists on the hosts,
 +
also it is necessary to allow passless access to primary host from secondary host as root and the script needs to be run under root user.
 +
 +
 +
== Script ==
 
  #!/bin/bash
 
  #!/bin/bash
 
  #from where to get GUI's data
 
  #from where to get GUI's data
  primaryhost=10.112.5.77
+
  primaryhost=1.2.3.4
 
   
 
   
 
  #if backups should be kept locally
 
  #if backups should be kept locally
Line 27: Line 37:
 
   rm $backupfilenamelocal
 
   rm $backupfilenamelocal
 
  fi
 
  fi
 +
 +
 +
== Crontab ==
 +
I placed it into /etc/crontab with line like following to backup and restore every 30 minutes
 +
*/30 * * * * root /root/voipmonitor/backup_and_restore.sh
 +
Then restart the crontab or send it HUP signall with kill command

Revision as of 17:49, 19 January 2023

= Description

Here follows the script used for peridically restore of settings from proimary db(GUI) on a backup GUI(db) host. (can be used with migration instance to mirror also GUI settings not only calldata)


Requirements

the script requires to set at least **primaryhost** variable, folders defined by backupfilenameremote and backupfilenamelocal needs to exists on the hosts,

also it is necessary to allow passless access to primary host from secondary host as root and the script needs to be run under root user.


Script

#!/bin/bash
#from where to get GUI's data
primaryhost=1.2.3.4

#if backups should be kept locally
keepbackups=true

datestr=`date +'%Y%m%d-%H%M'`
backupfilenameremote="/root/voipmonitor/backupGUI_$datestr.zip"
backupfilenamelocal="/root/voipmonitor/backup/backupGUI_$datestr.zip"
remotecmdstr="cd /var/www/html; php php/run.php backupGuiTables -t config -f $backupfilenameremote"

#create backup on primary
ssh $primaryhost $remotecmdstr
#get the backup
scp -q $primaryhost:/$backupfilenameremote $backupfilenamelocal

#remove the backup file on the primary after copied
ssh $primaryhost "rm $backupfilenameremote"

#apply the backup here
cd /var/www/html
#echo php/run.php restoreGuiTables -t config -f $backupfilenamelocal
php php/run.php restoreGuiTables -t config -f $backupfilenamelocal

if [ "$keepbackups" = false ] ; then
  rm $backupfilenamelocal
fi


Crontab

I placed it into /etc/crontab with line like following to backup and restore every 30 minutes

*/30 * * * * root /root/voipmonitor/backup_and_restore.sh

Then restart the crontab or send it HUP signall with kill command