檔案備份
在 ext2 或 ext3 的檔案系統中,可以使用 dump 指令來備份資料,還原則用 restore 指令來將資料還原。例如:
#dump -0u -f /dev/nst1 /home
是要將 /home 檔案系統用完整備份 (level 0 完整備份, level 1~9 是為增量備份) 的方式備份到 /dev/nst1 磁帶機中 (-f 參數是指備份成一般檔案或磁帶機或軟碟裝置),且在成功備份後更新 /etc/dumpdates 裡面的資料 (-u 參數,這例子中 /home 是某個分割區的掛載點不是一個單純的目錄,所以才能使用 -u 參數,如果只是備份某個資料夾,當然還是可以備份,可是 -u 參數則不適用)。
例:
# dump -0 -u -f boot.bak /boot
DUMP: Unknown format in /etc/dumpdates, line 1
DUMP: Date of this level 0 dump: Sat Apr 4 09:34:41 2009
DUMP: Dumping /dev/sda1 (/boot) to boot.bak
DUMP: Label: /boot
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 16461 blocks.
DUMP: Volume 1 started with block 1 at: Sat Apr 4 09:34:41 2009
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing boot.bak
DUMP: Volume 1 completed at: Sat Apr 4 09:34:44 2009
DUMP: Volume 1 16550 blocks (16.16MB)
DUMP: Volume 1 took 0:00:03
DUMP: Volume 1 transfer rate: 5516 kB/s
DUMP: 16550 blocks (16.16MB) on 1 volume(s)
DUMP: finished in 3 seconds, throughput 5516 kBytes/sec
DUMP: Unknown format in /etc/dumpdates, line 1
DUMP: Date of this level 0 dump: Sat Apr 4 09:34:41 2009
DUMP: Date this dump completed: Sat Apr 4 09:34:44 2009
DUMP: Average transfer rate: 5516 kB/s
DUMP: DUMP IS DONE
其中,-n 這個參數代表的是 level,備份的等級,每次備份時會依照給予的等級到 /etc/dumpdates 去找前一次等級比較小的備份,然後以那次備份作為基準點,製作增量備份。
還原可用 restore:
# restore -tvf boot.bak (查閱備份檔案的內容)
Verify tape and initialize maps
Input is from a local file/pipe
Input block size is 32
Dump date: Sat Apr 4 09:34:41 2009
Dumped from: the epoch
Level 0 dump of /boot on rhel5:/dev/sda1
Label: /boot
Extract directories from tape
Initialize symbol table.
dir 2 .
dir 11 ./lost+found
dir 12049 ./grub
leaf 12051 ./grub/grub.conf
leaf 12050 ./grub/splash.xpm.gz
leaf 12052 ./grub/menu.lst
leaf 12053 ./grub/device.map
leaf 12054 ./grub/stage1
leaf 12055 ./grub/stage2
leaf 12056 ./grub/e2fs_stage1_5
leaf 12057 ./grub/fat_stage1_5
leaf 12058 ./grub/ffs_stage1_5
leaf 12059 ./grub/iso9660_stage1_5
leaf 12060 ./grub/jfs_stage1_5
leaf 12061 ./grub/minix_stage1_5
leaf 12062 ./grub/reiserfs_stage1_5
leaf 12063 ./grub/ufs2_stage1_5
leaf 12064 ./grub/vstafs_stage1_5
leaf 12065 ./grub/xfs_stage1_5
leaf 16 ./initrd-2.6.18-8.el5PAE.img
leaf 12 ./System.map-2.6.18-8.el5PAE
leaf 13 ./config-2.6.18-8.el5PAE
leaf 14 ./symvers-2.6.18-8.el5PAE.gz
leaf 15 ./vmlinuz-2.6.18-8.el5PAE
leaf 21 ./initrd-2.6.18-8.el5.img
leaf 17 ./System.map-2.6.18-8.el5
leaf 18 ./config-2.6.18-8.el5
leaf 19 ./symvers-2.6.18-8.el5.gz
leaf 20 ./vmlinuz-2.6.18-8.el5
leaf 28 ./initrd-2.6.18-8.el5xen.img
leaf 22 ./System.map-2.6.18-8.el5xen
leaf 23 ./config-2.6.18-8.el5xen
leaf 24 ./symvers-2.6.18-8.el5xen.gz
leaf 25 ./vmlinuz-2.6.18-8.el5xen
leaf 26 ./xen-syms-2.6.18-8.el5
leaf 27 ./xen.gz-2.6.18-8.el5
restore 指令的使用方式是:
#restore -rvf DUMP_FILE (還原至當下目錄)
#restore -rvf DUMP_FILE /dev/sda1 (還原至 /dev/sda1 裝置)
#restore -ivf DUMP_FILE (進入互動模式,進入之後可用 ls, cd, add, delete, extract, exit 指令來操作)
==============================
rsync
rsync 可使用 ssh 通訊協定來傳輸資料,它比 scp 快且可以作差異上傳,它常用的參數:
-v:詳細模式
-e command:指定外部的程式來作為傳輸方式
-a:遞迴傳輸子目錄,且保留權限
-r:遞迴傳輸子目錄,但不保留權限
-l:重建符號連結
–partial:續傳部份檔案
–progress:顯現傳輸進度
-P:等於使用 –partital –progress
-p:保留權限
-A:保留 ACL 權限
-X:保留其他擴充權限
-R:保留參照路徑
例:
#rsync -alvR 192.168.0.2:/backup /boot (將本機 /boot 目錄傳送到 192.168.0.2 的 /backup 目錄中)