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: , ,

find and execute

find -name "*.rar" -exec unrar e {} \;
recursively searches for rar files, extracts the contents of each. matching filenames are substitutes in for the {} and executed, one at a time. this can be slower than piping the results of find to xargs, but doesnt fail when the executed command can only work on one file at a time.

Labels: ,

.bash_profile

export EDITIOR=vim
sets vim to be the default editor. it's probably not kosher to leave off the path, but it varies a lot between systems, so i just trust it's going to be available within $PATH

complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh
I'll happily admit this is voodoo to me, I could probably dissect how it works but i dont really care. takes hosts found in ~/.ssh/known_hosts and autocompletes them like filenames


alias ls='ls -FG'
alias ll='ls -FGl'
alias la='ls -aFGl'

colourful ls' with symbols to denote executable files and directories


alias h='history'
alias hg='history|grep'

less keystrokes for history and search of history means I use it more often

alias cp='cp -v'
I like to know the progress of long copy operations

alias df='df -H'
alias du='du -H'

who cares about bytes when you're dealing with hundreds of gigabytes. human readable please!

alias rm='rm -i'
saves me from brainfarts. overridden by rm -f

alias curl-easy="curl -C - -O "
an alias to make curl work more like fetch or wget. resumes automatically, saves the downloaded data named the same as it is on the server

Labels: ,

.inputrc

ok, this one is super short

set completion-ignore-case On
makes bash tab completion ignore case for file and directory names

Labels: ,