简单的全网备份脚本样板
web服务器每天定时推送的脚本
#!/bin/bash ip=`hostname -I` [ -d /backup ] || mkdir -p /backup [ -d /cup ] || mkdir -p /cup [ -d /cup/a ] || mkdir -p /cup/a ##开始打包并移动 \cp /var/spool/cron/root /cup/a/ \cp /etc/rc.local /cup/a/ \cp /etc/sysconfig/iptables /cup/a/ cd /cup tar -zcf "$ip"_$(date +%F-%w)_w.tar.gz a mv /cup/*.tar.gz /backup find /backup -mtime +7 | xargs rm -rf ##开始同步 md5sum /backup/* > /backup/mum.md5 [ $? -eq 0 ] || exit i=o while : do rsync -avzp /backup rsync_backup@192.168.200.130::backup --password-file=/etc/rsync.password sleep 3 let i++ [ $i -eq 2 ] && break done
备份服务器的脚本
#!/bin/bash bak1=/backupmon tm=`date` function mon(){ find /backup -name "*1_w*" | xargs -i mv {} $back1 } #function lujin (){ #for i in /backup/* #do # echo $i #done # #} #lu=`lujin` bak1=/backupmon [ -d $back1 ] || mkdir -p $back1 md5sum -c /backup/mum.md5 if [ $? -eq 0 ];then echo "ok" else echo "文件推送不全" && exit fi find /backup -name "*1_w*" | xargs -i mv {} $back1 find /backup/* -mtime +180 | xargs rm -rf ~
inotify+rsync实时推送脚本,样板
#!/bin/bash Path=/data backup_Server=192.168.200.130 /usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data | while read line do if [ -f $line ];then rsync -az $line --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password else cd $Path &&\ rsync -az ./ --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password fi done
mysql全部脚本样本
#!/bin/bash week=`date +%w` yonghu=root mima=123123 dir=/data find $dir -mtime +30 | xargs rm -rf if [ $week -eq 7 ] ;then mysqldump -u$yongh -p$miam --opt --all-databases > $dir/mysql.all_$(date +%F).sql fi rsync -avzp $dir rsync_backup@192.168.200.130::mysql --password-file=/etc/rsync.password