Skip to content

Instantly share code, notes, and snippets.

@kevashcraft
Last active December 2, 2018 22:43
Show Gist options
  • Save kevashcraft/52887499775297803890 to your computer and use it in GitHub Desktop.
Save kevashcraft/52887499775297803890 to your computer and use it in GitHub Desktop.
Recursive backup w rsync - bash script
#!/bin/bash
DESTINATION="/Backup"
SOURCE="/var/www"
#Todays date in ISO-8601 format:
DAY0=`date -I`
#Previous backup date:
DAY1=`find $DESTINATION/* -type d -prune -not -wholename "*lost+found*" | tail -1`
#The target directory:
TRG="$DESTINATION/$DAY0"
#The link destination directory:
LNK="$DAY1"
#The rsync options:
OPT="-avh --delete --link-dest=$LNK"
#Execute the backup
rsync $OPT $SOURCE $TRG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment