備份全網伺服器資料
阿新 • • 發佈:2018-11-05
客戶端推送指令碼
#!/bin/bash
Time=`date +%F-%w`
name=`hostname -I`
[ -d /backup] || mkdir /backup
[ -d /backup/bak ] || mkdir /backup/bak
rsync /var/spool/cron/root /backup/bak
rsync /etc/rc.d/rc.local /backup/bak
rsync /server/scripts /backup/bak
rsync /etc/sysconfig/iptables /backup/bak
cd /backup
mkdir $name
cd /backup
tar zcfP $Time.tar.gz bak
mv /backup/$Time* /backup/$name
cd /backup/$name
md5sum $Time* > $Time.txt
rsync -avz /backup/$name [email protected].168.200.10::backup --password-file=/etc/rsync.password
find -type f -mtime +7 | xargs rm -f
服務端檢查指令碼
#!/bin/bash
name=`date +%F-%w`
for i in `ls /backup`
do
cd /backup/$i
if [ -f $name.txt ];then
md5sum -c $name.txt
if [ $? -eq 0 ];then
echo "$i 傳輸成功"
else
echo "$i 傳輸失敗"
fi
else
echo "$i 傳輸失敗"
fi
find . -type f ! -name "*-1" -mtime +180 | xargs rm -f
done
mysql全備推送指令碼
#!/bin/bash
Time=`date +%F-%w`
name=`hostname -I`
[ -d /backup] || mkdir /backup
[ -d /backup/bak ] || mkdir /backup/bak
mysqldump -uroot -p666666 --all-databases > /backup/bak
cd /backup
mkdir $name
cd /backup
tar zcfP $Time.tar.gz bak
mv /backup/$Time* /backup/$name
cd /backup/$name
md5sum $Time* > $Time.txt
rsync -avz /backup/$name [email protected].168.200.10::backup --password-file=/etc/rsync.password
find -type f -mtime +7 | xargs rm -f
監控nfs實時同步指令碼
#!/bin/bash
Path=/data
backup_Server=192.168.200.10
/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.password
else
cd $Path &&\
rsync -az ./ --delete [email protected]$backup_Server::nfsbackup --password-file=/etc/rsync.password
fi
done
監控mysql實時同步
#!/bin/bash
Path=/usr/local/mysql/data
backup_Server=192.168.200.10
/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /usr/local/mysql/data | while read line
do
if [ -f $line ];then
rsync -az $line --delete [email protected]$backup_Server::mysqlbackup --password-file=/etc/rsync.password
else
cd $Path &&\
rsync -az ./ --delete [email protected]$backup_Server::mysqlbackup --password-file=/etc/rsync.password
fi
done
~