Complete Asterisk Backup Automatically
本帖最後由 TsinTsin 於 2011-12-5 01:03 編輯
Automatically backup script " /backup/backupwk.sh"
Add the script to crontab "/etc/crontab"- #
- #===============================================
- #
- # Copyright (c) 2011 IVE-ST 71302F-4C
- #Title : Complete System Backup
- #Version : v1.0 (18/09/2011)
- #Author : Alpha Tam
- #
- #===============================================
- #
- # Set shell execution path
- PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH
- export LANG=C
- # Get current time
- stamp=`date +%Y-%m-%d`
- # Backup to directory
- basedir=/backup/weekly/
- tempdir=/tmp/allbackup/
- todir=$basedir$stamp
- postfix=$tempdir/etc/postfix
- ssh=$tempdir/etc/ssh
- httpd=$tempdir/etc/httpd
- sslcert=$tempdir/usr/local/apache/conf
- fail2ban=$tempdir/etc/fail2ban
- html=$tempdir/var/www/html
- etcasterisk=$tempdir/etc/asterisk
- etcdahdi=$tempdir/etc/dahdi
- asteriskmohmp3=$tempdir/var/lib/asterisk/mohmp3
- asterisksoundscustom=$tempdir/var/lib/asterisk/sounds/custom
- asteriskvoicemail=$tempdir/var/spool/asterisk/voicemail
- asteriskmodules=$tempdir/usr/lib/asterisk/modules
- # check directory, if no make dir
- for dirs in $todir $tempdir $postfix $ssh $httpd $sslcert $fail2ban $etcasterisk $etcdahdi $asteriskmohmp3 $asterisksoundscustom $asteriskvoicemail $asteriskmodules $html
- do
- [ ! -d "$dirs" ] && mkdir -p $dirs
- done
- # 1. copy file to temp directory
- cp -a /etc/postfix/* $postfix
- cp -a /etc/ssh/* $ssh
- cp -a /etc/httpd/* $httpd
- cp -a /usr/local/apache/conf/* $sslcert
- cp -a /etc/fail2ban/* $fail2ban
- cp -a /etc/{crontab,hosts.allow,hosts.deny,my.cnf,php.ini,syslog.conf} $tempdir/etc
- cp -a /etc/asterisk/* $etcasterisk
- cp -a /etc/dahdi/* $etcdahdi
- cp -a /var/lib/asterisk/mohmp3/* $asteriskmohmp3
- cp -a /var/lib/asterisk/sounds/custom/* $asterisksoundscustom
- cp -a /var/spool/asterisk/voicemail/* $asteriskvoicemail
- cp -a /usr/lib/asterisk/modules/* $asteriskmodules
- cp -a /var/www/html/* $html
- mysql=$todir/mysql.$stamp.tar.bz2
- home=$todir/home.$stamp.tar.bz2
- log=$todir/log.$stamp.tar.bz2
- etcusrvar=$todir/etc.usr.var.$stamp.tar.bz2
- asteriskmonitor=$todir/asterisk.monitor.$stamp.tar
- # 5. tar temdir etc usr var
- cd $tempdir
- tar -jpc -f $etcusrvar etc usr var
- # 2. backup MysQL (/var/lib/mysql)
- cd /var/lib
- tar -jpc -f $mysql mysql
- # 3. backup home (/home)
- cd /
- tar -jpc -f $home home
-
- # 4. backup log (/var/log)
- cd /var
- tar -jpc -f $log log
-
- # 6. tar asterisk monitor (/var/spool/asterisk/monitor/)
- cd /var/spool/asterisk
- tar -c -f $asteriskmonitor monitor
-
- # 7. del asterisk monitor and temdir files
- \rm -r /var/spool/asterisk/monitor/*
- \rm -r $tempdir
- date21=`date --date='21 days ago' +%Y-%m-%d`
- # 8. automatically delete the old backup file after 3x7=21 days
- \rm -r $basedir$date21
複製代碼 |