簡單的全網備份指令碼樣板
阿新 • • 發佈:2018-11-01
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[email protected]::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 [email protected]$backup_Server::nfsbackup --password-file=/etc/rsync.passwordelse cd $Path &&\ rsync -az ./ --delete [email protected]$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 [email protected]192.168.200.130::mysql --password-file=/etc/rsync.password