远程自动备份脚本

 #!/bin/bash
cd /var/bak
time=`date +%w`
if [ $time -eq 6  ];then       #每周6全备份
ssh 192.168.20.5 "cd /var/webbackup && tar -cvf backupfull-web`date +%F`.tar /var/wwwroot"
ssh 192.168.20.6 "cd /var/dbbackup && tar -cvf backupfull-db`date +%F`.tar /var/mysqldb"

else                           #周6其他时间为增量备份
ssh 192.168.20.5 "cd /var/webbackup && tar -g backup  -cvf backup-web`date +%F`.tar /var/wwwroot"
ssh 192.168.20.6 "cd /var/dbbackup && tar -g backup -cvf backup-db`date +%F`.tar /var/mysqldb"
fi
#把备份文件发送到别分服务器
rsync -avz -e ssh 192.168.20.5:/var/webbackup /var/bak
rsync -avz -e ssh 192.168.20.6:/var/dbbackup /var/bak

你可能感兴趣的:(linux,自动备份)