Created
November 9, 2013 17:18
-
-
Save takumakei/7387615 to your computer and use it in GitHub Desktop.
任意のディレクトリをrsyncで同期バックアップするシェルスクリプト
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 | |
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