1. 程式人生 > >備份全網伺服器資料

備份全網伺服器資料

客戶端推送指令碼

 
  1. #!/bin/bash
  2. Time=`date +%F-%w`
  3. name=`hostname -I`
  4. [ -d /backup] || mkdir /backup
  5. [ -d /backup/bak ] || mkdir /backup/bak
  6. rsync /var/spool/cron/root /backup/bak
  7. rsync /etc/rc.d/rc.local /backup/bak
  8. rsync /server/scripts /backup/bak
  9. rsync /etc/sysconfig/iptables /backup/bak
  10. cd /backup
  11. mkdir $name
  12. cd /backup
  13. tar zcfP $Time.tar.gz bak
  14. mv /backup/$Time* /backup/$name
  15. cd /backup/$name
  16. md5sum $Time* > $Time.txt
  17. rsync -avz /backup/$name [email protected].168.200.10::backup --password-file=/etc/rsync.password

find -type f -mtime +7 | xargs rm -f

服務端檢查指令碼

 
  1. #!/bin/bash
  2. name=`date +%F-%w`
  3. for i in `ls /backup`
  4. do
  5. cd /backup/$i
  6. if [ -f $name.txt ];then
  7. md5sum -c $name.txt
  8. if [ $? -eq 0 ];then
  9. echo "$i 傳輸成功"
  10. else
  11. echo "$i 傳輸失敗"
  12. fi
  13. else
  14. echo "$i 傳輸失敗"
  15. fi
  16. find . -type f ! -name "*-1" -mtime +180 | xargs rm -f

done

mysql全備推送指令碼

 
  1. #!/bin/bash
  2. Time=`date +%F-%w`
  3. name=`hostname -I`
  4. [ -d /backup] || mkdir /backup
  5. [ -d /backup/bak ] || mkdir /backup/bak
  6. mysqldump -uroot -p666666 --all-databases > /backup/bak
  7. cd /backup
  8. mkdir $name
  9. cd /backup
  10. tar zcfP $Time.tar.gz bak
  11. mv /backup/$Time* /backup/$name
  12. cd /backup/$name
  13. md5sum $Time* > $Time.txt
  14. rsync -avz /backup/$name [email protected].168.200.10::backup --password-file=/etc/rsync.password

find -type f -mtime +7 | xargs rm -f

監控nfs實時同步指令碼

 
  1. #!/bin/bash
  2. Path=/data
  3. backup_Server=192.168.200.10
  4. /usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data | while read line
  5. do
  6. if [ -f $line ];then
  7. rsync -az $line --delete [email protected]$backup_Server::nfsbackup --password-file=/etc/rsync.password
  8. else
  9. cd $Path &&\
  10. rsync -az ./ --delete [email protected]$backup_Server::nfsbackup --password-file=/etc/rsync.password
  11. fi

done

監控mysql實時同步

 
  1. #!/bin/bash
  2. Path=/usr/local/mysql/data
  3. backup_Server=192.168.200.10
  4. /usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /usr/local/mysql/data | while read line
  5. do
  6. if [ -f $line ];then
  7. rsync -az $line --delete [email protected]$backup_Server::mysqlbackup --password-file=/etc/rsync.password
  8. else
  9. cd $Path &&\
  10. rsync -az ./ --delete [email protected]$backup_Server::mysqlbackup --password-file=/etc/rsync.password
  11. fi
  12. done
  13. ~

image_1crgu8b05tfp1t2u6q67qf5bj9.png-26.7kB