Last active
September 26, 2017 03:11
-
-
Save openroc/fec064205f46efefad00 to your computer and use it in GitHub Desktop.
backup.sh for mackup
This file contains hidden or 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 | |
# quick back file or dir via ln into Dropbox for syncing | |
BACKUPDIR=~/Dropbox/Mackup | |
PWD=`pwd` | |
function backup() { | |
target=${PWD}/$1; | |
echo "Start to backup $target" | |
# get filename | |
filepath=${target%/*} | |
filename=${target##*/} | |
if [ -e ${BACKUPDIR}/$filename ]; then | |
diffct=`diff $target ${BACKUPDIR}/$filename` | |
echo "Find $filename in ${BACKUPDIR}" | |
echo "diff >>>" | |
echo "$diffct" | |
echo "failed!!" | |
exit 125 | |
fi | |
# link | |
( | |
cd $filepath && | |
mv $filename $BACKUPDIR && | |
ln -s ${BACKUPDIR}/$filename $filename | |
) | |
} | |
if [ "$1" == "" ]; then | |
echo "Usage: backup.sh filename" | |
exit 126 | |
fi | |
if [ ! -e $1 ]; then | |
echo "Can't find $1" | |
exit 127 | |
fi | |
backup $1 | |
echo "success!!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment