rsync异地备份脚本
mkdir -p /data/shells
echo "asde#zYfcJ1231235" > /etc/server.pass
chmod 600 /etc/server.pass
cd /data/shells
cat > /data/shells/push_sj.sh <<'EOF'
#!/bin/bash
###结束现有rsync进程
killall `ps aux|grep rsync|awk -F" " '{print $11}'`
killall `ps aux|grep rsync|awk -F" " '{print $11}'`
echo 结束时间 `date +%F_%H%M%S` > /tmp/rsync_process.log
echo '###################结 束 时 间 ######################' >> /tmp/rsync_process.log
yuan="/home/test/test123"
mudi1="[email protected]::backup"
mudi2="07test/02YEWU/192.168.120.129"
#源和目的数据保持一致,会删除多余的文件,慎用
cs="-ravzPH --delete --force --ignore-errors"
#剔除目录/test/log,剔除文件/test/nohup.out --exclude '/test/log' --exclude '/test/nohup.out'
rsync $cs --password-file=/etc/server.pass --exclude '/test/log' --exclude '/test/nohup.out' $yuan $mudi1/$mudi2 > /tmp/rsync_centos.log
echo 完成时间 `date +%F_%H%M%S` >> /tmp/rsync_process.log
echo '###################完 成 时 间 ######################' >> /tmp/rsync_process.log
EOF
chmod +x /data/shells/*sh
TASK="0 22 * * * /data/shells/push_sj.sh"
(crontab -l; echo "$TASK") | crontab -
crontab -l