
我使用 rsync 進行備份:
rsync -a --link-dest=PATHTO/$PREVIOUSBACKUP $SOURCE $CURRENTBACKUP
這樣我就可以透過使用硬連結來節省空間。
當我需要備份一個總是在變化的大檔案(虛擬機器映像)時,就會出現問題。
是否可以不硬連結整個圖像,而只硬連結更改的部分?有沒有什麼工具可以解決這個問題?
答案1
這裡可以做很多事情。請注意,它們實際上都沒有使用硬鏈接,因為它們只能指向完整文件。使用btrfs
檔案系統在這裡開闢了一些非常有用的可能性。請注意,btrfs
目前(最新版本是 v3.13)仍處於實驗階段。然而,其乳牛(寫時複製)能力對於這種事情來說是完美的(當然,前提是在同一文件系統上進行備份是可以接受的)。考慮btrfs
安裝在 上的檔案系統/mnt
,您可以使用以下命令建立整個檔案系統的原子快照:
btrfs subvolume snapshot /mnt /mnt/snapshot
為了允許部分快照,您必須將要備份的檔案放在一個目錄中,subvolume
而不是一個目錄中。例如:
btrfs subvolume create /mnt/subvol
mv stuff /mnt/subvol
btrfs subvolume snapshot /mnt/subvol /mnt/subvol_snapshot
除了使用 之外btfrs
,您還可以考慮將虛擬機器映像安裝在備份的一側或兩側,並rsync
在兩個安裝點之間使用。
這個部落格顯示如何.vdi
使用安裝 Virtual Box 映像qemu-utils
。作為 root 的命令(未經測試):
modprobe nbd
qemu-nbd -c /dev/nbd0 <vdi-file>
mount /dev/nbd0p1 /mnt
...
umount /mnt
qemu-nbd -d /dev/nbd0
最後,可能有用的最簡單方法是--inplace
的選項rsync
。從手冊頁:
--inplace
This option changes how rsync transfers a file when its data needs to
be updated: instead of the default method of creating a new copy of the
file and moving it into place when it is complete, rsync instead writes
the updated data directly to the destination file.
...
This option is useful for transferring large files with block-based
changes or appended data, and also on systems that are disk bound, not
network bound.
--link-dest
當然,這裡的問題是,結合使用它(在 <2.6.4 版本中,兩者完全不相容)沒有任何好處,rsync
因為仍然必須在目標位置建立檔案的副本。