2009-03-21

Basic Non-destructive Backup with rsync (good for music & photos)

#!/bin/bash

EMAIL="me@myemailhost.com"
HOSTNAME="fileserver"
LOCAL_PATH="/mnt/data/photos/"
REMOTE_PATH="/Users/lucas/Pictures/iPhoto\ Library"
REMOTE_HOST="hackintosh"
WHAT="photos"

#if we've said to delete files that are missing in the remote copy, do so and exit
if [ $# -eq 1 ]; then
  if [ $1 == delete ];then
    rsync -ai --delete "$REMOTE_HOST":"$REMOTE_PATH" "$LOCAL_PATH"
    exit
  fi
fi

#otherwise backup changes
rsync -ai "$REMOTE_HOME":"$REMOTE_PATH" "$LOCAL_PATH" |mail -e -s "$HOSTNAME: $WHAT backed-up" $EMAIL

#and make a list of files that have been deleted in the remote copy
rsync -ain --delete "$REMOTE_HOME":"$REMOTE_PATH" "$LOCAL_PATH" |mail -e -s "$HOSTNAME: $WHAT to delete" $EMAIL



i have cron on my fileserver set to run this script every night (and another very similar one for my music). I just go about my business on my desktop using iphoto and itunes as normal and everything is replicated on my fileserver within 24 hours with email notification of what is copied or should be deleted from the backups. If I accidentally delete something from either library on my desktop, the files will still be sitting on my fileserver unharmed until I manually run the script with the "delete" argument.

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home