Skip to content

Instantly share code, notes, and snippets.

@wozozo
Created June 19, 2011 06:27
Show Gist options
  • Select an option

  • Save wozozo/1033828 to your computer and use it in GitHub Desktop.

Select an option

Save wozozo/1033828 to your computer and use it in GitHub Desktop.
#!/bin/bash
# config
SOURCES="/data /home/senko"
BACKUP_DIR="/backup/mypc"
# abort if any of the commands fail
set -e
todays=$(date +'%Y-%m-%d') # nicely sortable names for backups
last=$(ls -r | head -1)
to_delete=$(ls -r | tail -n +7) # will keep the last 6 backups
cd $BACKUP_DIR
ionice -c 3 nice -n +19 rsync -aq \
--link-dest=${BACKUP_DIR}/${last} $SOURCES $BACKUP_DIR/${todays}
# now we're safe to remove the old one(s)
[ -z "$to_delete" ] || rm -rf $to_delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment