Skip to content

Instantly share code, notes, and snippets.

@takumakei
Created November 9, 2013 17:18
Show Gist options
  • Save takumakei/7387615 to your computer and use it in GitHub Desktop.
Save takumakei/7387615 to your computer and use it in GitHub Desktop.
任意のディレクトリをrsyncで同期バックアップするシェルスクリプト
#!/bin/bash
function find-mount-point {
mount | grep $1 | awk '{print $3}'
}
function check-mount {
a=$(find-mount-point $1)
if [ "$a" = "" ]; then
b=/Volumes/$(basename $1)
if [ -e $b ]; then
echo "error: $b already exists"
exit 1
fi
mkdir $b
mount -t smbfs smb:$1 $b
a=$(find-mount-point $1)
if [ "$a" = "" ]; then
echo "error: $1 not found"
exit 1
fi
fi
echo $a
}
function backup {
a=$(find-mount-point $2)
b=$(check-mount $2)
c="/usr/local/bin/rsync -aPv --delete --exclude .DS_Store --delete-excluded $1 $b/$3"
echo $c
$c
[ "$a" = "" ] && umount $b
}
function backup-here {
a=$(cd $(dirname $0); pwd)
backup $a/ $1 $(basename $a)
}
## ~/Documents/Scans/ を //kei@oz/home の Scans にバックアップする
# backup ~/Documents/Scans/ //kei@oz/home Scans
## シェルスクリプトが存在するディレクトリをバックアップする
backup-here //kei@oz/home
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment