Skip to content

Instantly share code, notes, and snippets.

@aaronott
Created August 31, 2016 16:38
Show Gist options
  • Save aaronott/fd4e5da123ee6e02a1bed898c4852bdf to your computer and use it in GitHub Desktop.
Save aaronott/fd4e5da123ee6e02a1bed898c4852bdf to your computer and use it in GitHub Desktop.
#!/bin/sh
SOURCEDIR=/path/to/docroot
DESTDIR=/path/to/backup/dir
NAME=<site-name>
RETENTION=2
let MMIN=($RETENTION*60*24)-180
DATE=`date +%Y-%m-%d-%H-%M`
EXCLUDE=""
if [ ! -d $DESTDIR ]
then
/bin/mkdir -p $DESTDIR
fi
/usr/bin/find $DESTDIR -type f -name '*.tar.gz' -mmin +$MMIN | xargs /bin/rm -rf
/bin/tar -czf $DESTDIR/$NAME-$DATE.tar.gz $SOURCEDIR `if [[ -n "$EXCLUDE" ]]; then find $EXCLUDE -maxdepth 0 -print0 | while read -d $'\0' file; do echo " --exclude $file"; done; fi`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment