Board logo

標題: Complete Asterisk Backup Automatically [打印本頁]

作者: TsinTsin    時間: 2011-10-23 19:14     標題: Complete Asterisk Backup Automatically

本帖最後由 TsinTsin 於 2011-12-5 01:03 編輯

Automatically backup script " /backup/backupwk.sh"

Add the script to crontab "/etc/crontab"
  1. #
  2. #===============================================
  3. #
  4. # Copyright (c) 2011 IVE-ST 71302F-4C         
  5. #Title        :        Complete System Backup
  6. #Version        :        v1.0 (18/09/2011)
  7. #Author        :        Alpha Tam       
  8. #
  9. #===============================================
  10. #

  11. # Set shell execution path
  12. PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH
  13. export LANG=C

  14. # Get current time
  15. stamp=`date +%Y-%m-%d`

  16. # Backup to directory
  17. basedir=/backup/weekly/
  18. tempdir=/tmp/allbackup/
  19. todir=$basedir$stamp

  20. postfix=$tempdir/etc/postfix
  21. ssh=$tempdir/etc/ssh
  22. httpd=$tempdir/etc/httpd
  23. sslcert=$tempdir/usr/local/apache/conf
  24. fail2ban=$tempdir/etc/fail2ban
  25. html=$tempdir/var/www/html

  26. etcasterisk=$tempdir/etc/asterisk
  27. etcdahdi=$tempdir/etc/dahdi
  28. asteriskmohmp3=$tempdir/var/lib/asterisk/mohmp3
  29. asterisksoundscustom=$tempdir/var/lib/asterisk/sounds/custom
  30. asteriskvoicemail=$tempdir/var/spool/asterisk/voicemail
  31. asteriskmodules=$tempdir/usr/lib/asterisk/modules

  32. # check directory, if no make dir
  33. for dirs in $todir $tempdir $postfix $ssh $httpd $sslcert $fail2ban $etcasterisk $etcdahdi $asteriskmohmp3 $asterisksoundscustom $asteriskvoicemail $asteriskmodules $html
  34. do
  35.         [ ! -d "$dirs" ] && mkdir -p $dirs  
  36. done

  37. # 1. copy file to temp directory
  38. cp -a /etc/postfix/* $postfix
  39. cp -a /etc/ssh/* $ssh
  40. cp -a /etc/httpd/* $httpd
  41. cp -a /usr/local/apache/conf/* $sslcert
  42. cp -a /etc/fail2ban/* $fail2ban
  43. cp -a /etc/{crontab,hosts.allow,hosts.deny,my.cnf,php.ini,syslog.conf}        $tempdir/etc

  44. cp -a /etc/asterisk/* $etcasterisk
  45. cp -a /etc/dahdi/* $etcdahdi
  46. cp -a /var/lib/asterisk/mohmp3/* $asteriskmohmp3
  47. cp -a /var/lib/asterisk/sounds/custom/* $asterisksoundscustom
  48. cp -a /var/spool/asterisk/voicemail/* $asteriskvoicemail
  49. cp -a /usr/lib/asterisk/modules/* $asteriskmodules
  50. cp -a /var/www/html/* $html

  51. mysql=$todir/mysql.$stamp.tar.bz2
  52. home=$todir/home.$stamp.tar.bz2
  53. log=$todir/log.$stamp.tar.bz2
  54. etcusrvar=$todir/etc.usr.var.$stamp.tar.bz2
  55. asteriskmonitor=$todir/asterisk.monitor.$stamp.tar

  56. # 5. tar temdir etc usr var
  57. cd $tempdir
  58.   tar -jpc -f $etcusrvar etc usr var

  59. # 2. backup MysQL (/var/lib/mysql)
  60. cd /var/lib
  61.   tar -jpc -f $mysql mysql

  62. # 3. backup home (/home)
  63. cd /
  64.   tar -jpc -f $home home
  65.   
  66. # 4. backup log (/var/log)
  67. cd /var
  68.   tar -jpc -f $log log
  69.   
  70. # 6. tar asterisk monitor (/var/spool/asterisk/monitor/)
  71. cd /var/spool/asterisk
  72.   tar -c -f $asteriskmonitor monitor
  73.   
  74. # 7. del asterisk monitor and temdir files
  75. \rm -r /var/spool/asterisk/monitor/*
  76. \rm -r $tempdir

  77. date21=`date --date='21 days ago' +%Y-%m-%d`

  78. # 8. automatically delete the old backup file after 3x7=21 days
  79. \rm -r $basedir$date21
複製代碼

作者: TsinTsin    時間: 2011-10-23 19:18

本帖最後由 TsinTsin 於 2011-12-5 01:03 編輯

Passive Mode Synchronize the System Backup file to Windows with WinSCP:

ServerBackupSync.txt
  1. #
  2. #===============================================
  3. #
  4. # Copyright (c) 2011 IVE-ST 71302F-4C         
  5. #Title        :        Synchronize the System Backup file to Windows
  6. #Version        :        v1.0 (18/09/2011)
  7. #Author        :        Alpha Tam
  8. #
  9. #===============================================
  10. #
  11. option echo off

  12. # Automatically answer all prompts negatively not to stall the script on errors
  13. option batch on

  14. # Disable overwrite confirmations that conflict with the previous
  15. option confirm off

  16. # Connect using a password
  17. open scp://root:password@ip:22 -hostkey="ssh-rsa 2048 68:9d:0c:9a:11:8e:df:44:5c:72:9a:7a:45:92:4c:e9"

  18. # Change remote directory
  19. #cd /backup/weekly

  20. # Force binary mode transfer
  21. option transfer binary

  22. #get /backup/weekly f:\ServerBackup
  23. #put f:\ServerBackup /backup/weekly

  24. # Syn local|remote|both
  25. #synchronize remote -delete
  26. #synchronize both f:\ServerBackup /backup/weekly
  27. synchronize local f:\ServerBackup /backup/weekly

  28. # Closes session
  29. close

  30. # Closes all sessions and terminates the program
  31. Exit
複製代碼
Create the batch file and add to Windows Task Scheduler
ServerBackupSync.cmd
  1. @echo off

  2. "C:\Program Files (x86)\WinSCP\WinSCP.exe" /console /script=C:\Users\Administrator\Desktop\batch\ ServerBackupSync.txt /log=C:\Users\Administrator\Desktop\batch\log\ ServerBackupSync.log

  3. pause
複製代碼

作者: bubblestar    時間: 2011-10-23 20:46

Thanks for TsinTsin C-Hing's great backup script.  It will be very useful indeed.
作者: ckleea    時間: 2011-10-24 10:12

回復 3# bubblestar

Your scripts have been focused on a backup of the config files and database files. I wonder if you also use a mysql script for the database backup instead of directory backup. Although you can still be backup, sometimes file locking problem may make backup incomplete.
作者: TsinTsin    時間: 2011-10-24 11:24

本帖最後由 TsinTsin 於 2011-12-5 01:03 編輯

directory backup for file only, because I have the "Daily Database backup script" using mysqldump
  1. cd /home/xxx/backup
  2. stamp=`date +%Y-%m-%d`
  3. mysqldump -u_joomla -p*xxxxxxxx _joomla > joomla_db_$stamp.sql
  4. bzip2 -z -9 -f joomla_db_$stamp.sql
  5. #mutt xxx@vpnbest.com -a joomla_db_$stamp.sql.bz2 -s "Joomla Database Backup"
  6. uuencode /home/telltou/backup/joomla_db_$stamp.sql.bz2 joomla_db_$stamp.sql.bz2| mail -s 'Daily Backup - Joomla Database' xxx@vpnbest.com
  7. rm joomla_db_$stamp.sql.bz2
複製代碼

作者: ckleea    時間: 2011-10-24 11:47

回復 5# TsinTsin

This is I look for. Thanks




歡迎光臨 電訊茶室 (http://telecom-cafe.com/forum/) Powered by Discuz! 7.2