Created
August 16, 2010 16:47
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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