备份脚本 - 递归

时间:2016-12-24 15:46:12

标签: linux cron centos

我们希望使用以下备份脚本来浏览datavol文件夹中的每个目录,但它似乎在第4行失败。如果有人对如何做到这一点有更好的建议,请随时告诉我

for d in /home/datavol/ ; do
echo "$d"

tar -czf /backups/emalee-backup-$d-$(date +%Y-%m-%d).tar.gz /home/datavol/$d

scp -i /root/.ssh/id_rsa_backup /backups/emalee-backup-$d-$(date +%Y-%m-%d).tar.gz emalee-backup@peg.trinix.co:/home/emalee-backup/docker-backup

curl -X POST --data-urlencode 'payload={"channel": "#server","text": "We are all backed up. Good ol Emalee is safe on /"$d/". :pride:"}' https://hooks.slack.com/services/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

rm /backups/emalee-backup-$d-$(date +%Y-%m-%d).tar.gz -f

ssh -i /root/.ssh/id_rsa_backup emalee-backup@peg.trinix.co

find /home/emalee-backup/docker-backup/ -mtime +7 -exec rm -f {} \;

TODAYSDATE=$(date +%d)
if [ "$TODAYSDATE" == "01" ] ;
then
    cp /home/emalee-backup/docker-backup/emalee-backup-$d-$(date +%Y-%m-%d).tar.gz /home/emalee-backup/monthly-docker-backup/emalee-backup-$d-$(date +%Y-%m-%d).tar.gz
    curl -X POST --data-urlencode 'payload={"channel": "#server","text": "Archived a monthly backup for good ol Emalee on $d. :handbag:"}' https://hooks.slack.com/services/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
fi
done

logout

1 个答案:

答案 0 :(得分:1)

工作解决方案

for d in /home/datavol/hosts/* ; do

s="${d##*/}"

echo "$s"

tar -czf /backups/emalee-backup-$s-$(date +%Y-%m-%d).tar.gz $d

scp -i /root/.ssh/id_rsa_backup /backups/emalee-backup-$s-$(date +%Y-%m-%d).tar.gz emalee-backup@peg.trinix.co:/home/emalee-backup/docker-backup

curl -X POST --data-urlencode 'payload={"channel": "#server","text": "We are all backed up. Good ol Emalee is safe on "'"$s"'". :pride:"}' https://hooks.slack.com/services/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

rm /backups/emalee-backup-$s-$(date +%Y-%m-%d).tar.gz -f

done