我的 /var/www/html/ 文件夹中有多个站点,如下所示:-
/var/www/html/site-1
/var/www/html/site-2
/var/www/html/site-3
/var/www/html/site-4
我想压缩我的服务器上的每个站点并在 S3 存储桶上同步。
答案1
每个站点一个 zip 文件:
for num in $(seq 1 4); do zip -r "/tmp/backup-site-${num}.zip" "/var/www/html/site-${num}" && aws s3 cp "/tmp/backup-site-${num}.zip" "s3://yourbucketname/"; done
所有站点使用一个 zip 文件:
zip -r /tmp/site-backup.zip /var/www/html/site-[1-4] && aws s3 cp "/tmp/site-backup.zip" "s3://yourbucketname/"
答案2
#!/bin/bash
DATE=$(date +%d-%m-%Y)
BACKUP_DIR="/root/backup/web-backup"
# To create a new directory into backup directory location.
mkdir -p $BACKUP_DIR/$DATE
# take each website backup in separate name, use below format.
tar -zcvpf $BACKUP_DIR/website-1-$DATE.tar.gz /var/www/html/website-1
tar -zcvpf $BACKUP_DIR/website-2-$DATE.tar.gz /var/www/html/website-2
tar -zcvpf $BACKUP_DIR/website-3-$DATE.tar.gz /var/www/html/website-3
# Delete files older than 10 days
find $BACKUP_DIR/* -mtime +10 -exec rm {} \;
aws s3 sync $BACKUP_DIR code s3://code-backup-bucket --region us-west-1