Skip to content

Instantly share code, notes, and snippets.

@klang
Created August 16, 2010 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klang/527254 to your computer and use it in GitHub Desktop.
Save klang/527254 to your computer and use it in GitHub Desktop.
poor man's time capsule. Works with in cygwin as well as any unix based environment that provides rsync.
#!/bin/bash
semaphore() {
if [ -e $0.pid ]; then
PID=$(cat $0.pid)
fi
if [ $PID ]; then
echo $PID on file
PIDr=$( ps -ef | awk '{print $2}' | grep ^$PID$ )
fi
if [[ $PIDr && $PID ]]; then
echo $PIDr in memory
echo "$0 is running with PID $PID"
exit 1
fi
if [[ !$PIDr || $PID != $$ ]]; then
echo $$ > $0.pid
fi
}
semaphore
date=`date "+%Y%m%dT%H%M%S"`
PATHTOBACKUP=/Users/$USER
HOST=$USER@192.168.0.105
rsync -azP --filter='- *~' --delete --filter='- Backups' --link-dest=$PATHTOBACKUP/current $HOME $HOST:$PATHTOBACKUP/back-$
date
ssh $HOST "rm $PATHTOBACKUP/current && ln -s back-$date $PATHTOBACKUP/current"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment