Linux 環境自動備份檔案
1、先安裝rsync
yum install rsync
2、寫一個shell腳本rsync_file.sh
#!/usr/bin/env bash
function rsync_file(){
pwds='123456'
datestr=`date`
echo -e "\033[32m =========== 開始備份 ========== \033[0m"
# \033[32m的解釋見鏈接: https://blog.csdn.net/panpan639944806/article/details/23930553
echo -e "\033[31m [${datestr}] \033[0m"
/usr/bin/expect<<-EOF
set timeout 443200
spawn bash -c "rsync -avzu --progress /home/cj/* root@180.80.*.*:/opt/"
expect {
"*assword*" {send "$pwds\r"}
}
expect "total size is*"
send "exit\r"
expect eof
EOF
datestr2=`date`
echo -e "\033[32m =========== 備份結束 ========== \033[0m"
echo -e "\033[31m [${datestr2}] \033[0m"
}
rsync_file
3、設定定時任務
crontab -e
00 00 * * * sh /opt/rsync_file.sh >> /home/logs/log.log
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/286727.html
標籤:其他
上一篇:Bash命令的學習筆記~
