Skip to content

Instantly share code, notes, and snippets.

@openroc
Last active September 26, 2017 03:11
Show Gist options
  • Save openroc/fec064205f46efefad00 to your computer and use it in GitHub Desktop.
Save openroc/fec064205f46efefad00 to your computer and use it in GitHub Desktop.
backup.sh for mackup
#!/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