Skip to content

Instantly share code, notes, and snippets.

@klang
Created August 16, 2010 16:46
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/527250 to your computer and use it in GitHub Desktop.
Save klang/527250 to your computer and use it in GitHub Desktop.
poor man's time machine. 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"`
rsync -aH --filter='- *~' --delete --filter='- Backups' --link-dest=$HOME/Backups/current $HOME $HOME/Backups/back-$date
rm $HOME/Backups/current
ln -s back-$date $HOME/Backups/current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment