Skip to content

Instantly share code, notes, and snippets.

@anothergituser
Last active June 23, 2017 09:54
Show Gist options
  • Save anothergituser/c67e6815f0a1264f6765a76f2f62f747 to your computer and use it in GitHub Desktop.
Save anothergituser/c67e6815f0a1264f6765a76f2f62f747 to your computer and use it in GitHub Desktop.
rsync website backup script
#!/bin/bash
# Website Backup Script
# http://webgnuru.com/linux/rsync_incremental.php
# Adapted to be run by anacron
# before running the script for the first time
# full_incremental should contain a dir like 2017-01-01
# empty or having a full backup
cd full_incremental
#Todays date in ISO-8601 format:
NOW=`date -I`
#Last backup
LAST=`ls -r | head -1`
#The source directory:
SRC="root@remote:/var/www/vhosts/site/public/"
#The target directory:
TRG="/mnt/storage/backup/full_incremental/$NOW"
#The link destination directory:
LNK="/mnt/storage/backup/full_incremental/$LAST"
#The rsync options:
OPT="-avh -e ssh --delete --link-dest=$LNK"
#Execute the backup
rsync $OPT $SRC $TRG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment