Wednesday, August 15, 2007

Mac Tips:利用rsync作硬碟備份

使用Mac OS X的最大好處是,你可以善用他的BSD底層,使用Unix-like系統的各種小工具。當需要作備份的時候,在Windows上我需要付費的備份軟體,因為Windows內建的backup不太好用,在Mac上我則可以直接使用rsync和shellscript來滿足需求。

建立一個backup.sh檔,並使用chmod +x讓他可以執行。backup.sh內容可參考:#!/bin/sh

RSYNC="/usr/bin/rsync -E"
DEST="/Volumes/backup_disk"

# sudo runs the backup as root
# -a turns on archive mode (recursive copy + retain attributes)
# -x don't cross device boundaries (ignore mounted volumes)
# -S handle sparse files efficiently
# --delete deletes any files that have been deleted locally
# $* expands to any extra command line options you may give

sudo $RSYNC -a -v -x -S --delete \
--exclude-from backup_excludes.txt $* / $DEST

# make the backup bootable - comment this out if needed
sudo bless -folder $DEST/System/Library/CoreServices

另建立一個backup_excludes.txt,標明不需備份的目錄:/tmp/*
*/.Trash
.Spotlight-*/


參考資料:
http://www.egg-tech.com/mac_backup/

No comments: