-1

I have multiple sites in my /var/www/html/ folder like following:-

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

i want to zip each site on my server and to sync on s3 bucket.

Sukhjinder Singh
  • 1,944
  • 2
  • 8
  • 17

2 Answers2

0

One zip for each site:

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

One zip for all sites:

zip -r /tmp/site-backup.zip /var/www/html/site-[1-4] && aws s3 cp "/tmp/site-backup.zip" "s3://yourbucketname/"

Alberto Pau
  • 159
  • 5
0
#!/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
Sukhjinder Singh
  • 1,944
  • 2
  • 8
  • 17