Ubuntu

在 Ubuntu 上備份多個站點

  • January 16, 2020

我的 /var/www/html/ 文件夾中有多個站點,如下所示:-

/var/www/html/site-1 
/var/www/html/site-2 
/var/www/html/site-3
/var/www/html/site-4

我想壓縮我伺服器上的每個站點並在 s3 儲存桶上同步。

#!/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

每個站點一個 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/"

引用自:https://serverfault.com/questions/997492