dump備份
restore還原
dd資料備份
mkisofs鏡像檔案製作
dump備份
dump主要用於備份真箇檔案系統備份,雖然也可以備份單一目錄,但是對目錄的支援不足,單一目錄還是建議使用打包壓縮的方式進行備份
dump另一個只要功能就是制定等級,也就是可以進行增量備份。
dump等級分為0~9 10個等級,0是完全備份,1是在0的基礎上進行增量備份,依次類推
當待備份的資料為單一檔案系統
可以利用了level 0~9進行備份,同時可以使用dump完整功能
當待備份的資料只是目錄,並非單一檔案系統
限制:
所有備份資料必須都在該目錄下
僅能使用level 0 進行資料備份
不支援-u參數,即無法建立/etc/dumpdates這個level備份的時間記錄檔案
文法:dump [-Suvj] [-level] [-f備份檔案]待備份資料
dump -W
選項與參數:
-S:僅列出後面的待備份資料需要多少磁碟空間才能夠備份完畢
-u:將這次備份記錄到/etc/dumpdates檔案中
-v:將dump檔案過程顯示出來
-j:加入bzip2的支援,將資料進行壓縮,預設壓縮等級2
-level:備份等級0~9
-f:備份檔案
-W:列出在/etc/fstab裡面的具有dump設定的分區是否有過備份
舉例1:備份掛載到/boot檔案系統 level -0
[root@localhost ~]# dump -S /boot16752640[root@localhost ~]# dump -u -0 -f /root/boot.dump.0 /boot DUMP: Date of this level 0 dump: Fri Feb 28 15:05:56 2014 DUMP: Dumping /dev/sda1 (/boot) to /root/boot.dump.0 DUMP: Label: /boot DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 16360 blocks. DUMP: Volume 1 started with block 1 at: Fri Feb 28 15:05:56 2014 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /root/boot.dump.0 DUMP: Volume 1 completed at: Fri Feb 28 15:05:58 2014 DUMP: Volume 1 16440 blocks (16.05MB) DUMP: Volume 1 took 0:00:02 DUMP: Volume 1 transfer rate: 8220 kB/s DUMP: 16440 blocks (16.05MB) on 1 volume(s) DUMP: finished in 2 seconds, throughput 8220 kBytes/sec DUMP: Date of this level 0 dump: Fri Feb 28 15:05:56 2014 DUMP: Date this dump completed: Fri Feb 28 15:05:58 2014 DUMP: Average transfer rate: 8220 kB/s DUMP: DUMP IS DONE [root@localhost ~]# cat /etc/dumpdates /dev/sda1 0 Fri Feb 28 15:05:56 2014 +0800=>可以看出etc/dumpdates記錄著這次備份資訊
舉例2:查看檔案系統備份記錄
[root@localhost ~]# dump -WLast dump(s) done (Dump '>' file systems):> /dev/sda2 ( /) Last dump: never> /dev/sda3 ( /home) Last dump: never /dev/sda1 ( /boot) Last dump: Level 0, Dat> /dev/sda6 (/mnt/sda6) Last dump: never=>可以看出sda1已經進行了level0備份,其他還未備份
舉例3:增量備份 level 1
[root@localhost ~]# dd if=/dev/zero of=/boot/bigfile.img bs=1M count=2020+0 records in20+0 records out20971520 bytes (21 MB) copied, 0.320717 seconds, 65.4 MB/s=>先建立一個20M左右的檔案[root@localhost ~]# dump -u -1 -f /root/boot.dump.1 /boot DUMP: Date of this level 1 dump: Fri Feb 28 15:17:51 2014 DUMP: Date of last level 0 dump: Fri Feb 28 15:05:56 2014 DUMP: Dumping /dev/sda1 (/boot) to /root/boot.dump.1 DUMP: Label: /boot DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 20543 blocks. DUMP: Volume 1 started with block 1 at: Fri Feb 28 15:17:52 2014 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /root/boot.dump.1 DUMP: Volume 1 completed at: Fri Feb 28 15:17:53 2014 DUMP: Volume 1 20580 blocks (20.10MB) DUMP: Volume 1 took 0:00:01 DUMP: Volume 1 transfer rate: 20580 kB/s DUMP: 20580 blocks (20.10MB) on 1 volume(s) DUMP: finished in 1 seconds, throughput 20580 kBytes/sec DUMP: Date of this level 1 dump: Fri Feb 28 15:17:51 2014 DUMP: Date this dump completed: Fri Feb 28 15:17:53 2014 DUMP: Average transfer rate: 20580 kB/s DUMP: DUMP IS DONE[root@localhost ~]# cat /etc/dumpdates /dev/sda1 0 Fri Feb 28 15:05:56 2014 +0800/dev/sda1 1 Fri Feb 28 15:17:51 2014 +0800=>這次配備寫入備份記錄中[root@localhost ~]# dump -WLast dump(s) done (Dump '>' file systems):> /dev/sda2 ( /) Last dump: never> /dev/sda3 ( /home) Last dump: never /dev/sda1 ( /boot) Last dump: Level 1, Date Fri Feb 28 15:17:51 2014> /dev/sda6 (/mnt/sda6) Last dump: never[root@localhost ~]# ll /root/boot* -rw-r--r-- 1 root root 16834560 02-28 15:05 /root/boot.dump.0-rw-r--r-- 1 root root 21073920 02-28 15:17 /root/ boot.dump.1=> boot.dump.1大小約為20M,可見是增量備份
舉例4:單一目錄進行備份
[root@localhost ~]# dump -0 -f /root/etc.dump /etc DUMP: Date of this level 0 dump: Fri Feb 28 15:23:39 2014 DUMP: Dumping /dev/sda2 (/ (dir etc)) to /root/etc.dumpDUMP: Label: / DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 177675 blocks. DUMP: Volume 1 started with block 1 at: Fri Feb 28 15:23:41 2014 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /root/etc.dump DUMP: Volume 1 completed at: Fri Feb 28 15:24:23 2014 DUMP: Volume 1 188600 blocks (184.18MB) DUMP: Volume 1 took 0:00:42 DUMP: Volume 1 transfer rate: 4490 kB/s DUMP: 188600 blocks (184.18MB) on 1 volume(s) DUMP: finished in 42 seconds, throughput 4490 kBytes/sec DUMP: Date of this level 0 dump: Fri Feb 28 15:23:39 2014 DUMP: Date this dump completed: Fri Feb 28 15:24:23 2014 DUMP: Average transfer rate: 4490 kB/s DUMP: DUMP IS DONE[root@localhost ~]# ll /root/etc.dump -rw-r--r-- 1 root root 193126400 02-28 15:24 /root/etc.dump
restore還原
dump備份的檔案由restore進行還原
文法:
查看dump檔案:restore –t [-f dumpfile] [-h]
比較dump與實際檔案:restore –C [-f dumpfile] –D掛載點
進入互動模式(還原單個檔案):restore –i [-f dumpfile]
還原整個檔案系統:restore –r [-f dumpfile]
選項與參數:
相關的各種模式,各種模式無法混用.例如不可以寫 -tC
-t:此模式用在察看 dump起來的備份檔中含有什麼重要資料!類似 tar -t功能;
-C:此模式可以將 dump內的資料拿出來跟實際的檔案系統做比較,最終會列出[在 dump檔案內有記錄的,且目前檔案系統不一樣]的檔案;
-i:進入互動模式,可以僅還原部分檔案,用在 dump目錄時的還原
-r:將整個 filesystem還原的一種模式,用在還原針對檔案系統的 dump備份;
其他較常用到的選項功能:
-h:察看完整備份資料中的 inode與檔案系統 label等資訊
-f:後面就接你要處理的那個 dump檔案
-D:與 -C進行搭配,可以查出後面接的掛載點與 dump內有不同的檔案
舉例1:查看dump備份檔案
[root@localhost ~]# restore -t -f /root/boot.dump.0Dump date: Fri Feb 28 15:05:56 2014Dumped from: the epochLevel 0 dump of /boot on localhost.localdomain:/dev/sda1Label: /boot 2 . 11 ./lost+found 10041 ./grub 10059 ./grub/grub.conf……. 14 ./System.map-2.6.18-371.el5 15 ./config-2.6.18-371.el5 16 ./symvers-2.6.18-371.el5.gz 17 ./vmlinuz-2.6.18-371.el5
舉例2:比較檔案差異
[root@localhost ~]# mv /boot/message /boot/message-back[root@localhost ~]# restore -C -f /root/boot.dump.0 -D /bootDump date: Fri Feb 28 15:05:56 2014Dumped from: the epochLevel 0 dump of /boot on localhost.localdomain:/dev/sda1Label: /bootfilesys = /bootrestore: unable to stat ./message: No such file or directorySome files were modified! 1 compare errors
舉例3:還原整個檔案系統
[root@localhost ~]# dd if=/dev/zero of=/home/newfile bs=1M count=200200+0 records in200+0 records out209715200 bytes (210 MB) copied, 3.83857 seconds, 54.6 MB/s[root@localhost ~]# mkfs -t ext3 /home/newfile mke2fs 1.39 (29-May-2006)/home/newfile is not a block special device.……180 days, whichever comes first. Use tune2fs -c or -i to override.[root@localhost ~]# mount -o loop /home/newfile /mnt[root@localhost ~]# df -h檔案系統 容量 已用 可用 已用% 掛載點/dev/sda2 9.5G 4.4G 4.7G 49% //dev/sda3 4.8G 339M 4.2G 8% /home/dev/sda1 99M 42M 53M 45% /boottmpfs 1014M 0 1014M 0% /dev/shm/home/newfile 194M 5.6M 179M 4% /mnt=>建立一個檔案掛載到mnt下[root@localhost ~]# cd /mnt[root@localhost mnt]# restore -r -f /root/boot.dump.0restore: ./lost+found: File exists[root@localhost mnt]# ll總計 16149-rw-r--r-- 1 root root 70400 10-01 21:10 config-2.6.18-371.el5drwxr-xr-x 2 root root 1024 02-18 09:51 grub-rw------- 1 root root 2748313 02-18 09:46 initrd-2.6.18-371.el5.imgdrwx------ 2 root root 12288 02-14 18:00 lost+found-rw-r--r-- 1 root root 80032 2009-03-13 message-rw------- 1 root root 27676 02-28 15:54 restoresymtable-rw-r--r-- 1 root root 117436 10-01 21:10 symvers-2.6.18-371.el5.gz-rw-r--r-- 1 root root 996296 10-01 21:10 System.map-2.6.18-371.el5-rw-r--r-- 1 root root 10485760 02-28 13:25 testing.img-rw-r--r-- 1 root root 1912148 10-01 21:10 vmlinuz-2.6.18-371.el5=>還原level 0備份[root@localhost mnt]# restore -r -f /root/boot.dump.1[root@localhost mnt]# ll總計 36711-rw-r--r-- 1 root root 20971520 02-28 15:17 bigfile.img-rw-r--r-- 1 root root 70400 10-01 21:10 config-2.6.18-371.el5drwxr-xr-x 2 root root 1024 02-18 09:51 grub-rw------- 1 root root 2748313 02-18 09:46 initrd-2.6.18-371.el5.imgdrwx------ 2 root root 12288 02-14 18:00 lost+found-rw-r--r-- 1 root root 80032 2009-03-13 message-------- 1 root root 27724 02-28 15:55 restoresymtable-rw-r--r-- 1 root root 117436 10-01 21:10 symvers-2.6.18-371.el5.gz-rw-r--r-- 1 root root 996296 10-01 21:10 System.map-2.6.18-371.el5-rw-r--r-- 1 root root 10485760 02-28 13:25 testing.img-rw-r--r-- 1 root root 1912148 10-01 21:10 vmlinuz-2.6.18-371.el5=>還原level 1備份可以看到多了bigfile.img這個增量檔案
dd
dd功能不僅限於建立檔案,更多功能在於“備份”,cp,dump只是簡單的檔案資料拷貝,而dd可以讀取裝置的所有內容,比如superblock ,boot sector,mete data等
文法:dd if=”input file” of=”output file” bs=”block” count=”number”
選項與參數:
if:輸入檔案,也可以是裝置
of:輸出檔案,也可以是裝置
bs:每個block的大小,預設是512K
count:block數量
舉例1.檔案備份
[root@localhost ~]# dd if=~/.bashrc of=/tmp/bashrc 0+1 records in0+1 records out176 bytes (176 B) copied, 7.3142e-05 seconds, 2.4 MB/s[root@localhost ~]# ll /tmp/bashrc -rw-r--r-- 1 root root 176 02-28 16:17 /tmp/bashrc
舉例2:檔案系統備份
[root@localhost ~]# dd if=/dev/sda1 of=/tmp/boot.dd bs=1M 101+1 records in101+1 records out106896384 bytes (107 MB) copied, 9.60492 seconds, 11.1 MB/s[root@localhost ~]# ll /tmp/boot.dd-rw-r--r-- 1 root root 106896384 02-28 16:19 /tmp/boot.dd
舉例3:檔案系統還原
[root@localhost ~]# dd if=/tmp/boot.dd of=/dev/sda1 bs=1M
舉例4.檔案系統完全複製
Dump備份時,我們需要先用Dump將檔案系統備份,然後建立新的檔案系統,格式化,再將備份檔案還原到新的檔案系統。
使用dd可以不用格式化,就可以完全複製一個檔案系統,因為dd將uperblock ,boot sector,mete data等資訊都進行複製,格式化要做的不也正是這些事嗎
[root@bogon ~]# fdisk /dev/sda…….Command (m for help): n……Command (m for help): P…… Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux……/dev/sda7 2116 2134 152586 83 LinuxCommand (m for help): w……[root@bogon ~]# partprobe=>建立完分區[root@bogon ~]# dd if=/dev/sda1 of=/dev/sda7 208782+0 records in208782+0 records out106896384 bytes (107 MB) copied, 23.5363 seconds, 4.5 MB/s[root@bogon ~]# mount /dev/sda7 /mnt[root@bogon ~]# ll /mnt總計 5838-rw-r--r-- 1 root root 70400 10-01 21:10 config-2.6.18-371.el5drwxr-xr-x 2 root root 1024 02-18 20:26 grub-rw------- 1 root root 2748762 02-27 19:45 initrd-2.6.18-371.el5.imgdrwx------ 2 root root 12288 02-19 03:59 lost+found-rw-r--r-- 1 root root 80032 2009-03-13 message-rw-r--r-- 1 root root 117436 10-01 21:10 symvers-2.6.18-371.el5.gz-rw-r--r-- 1 root root 996296 10-01 21:10 System.map-2.6.18-371.el5-rw-r--r-- 1 root root 1912148 10-01 21:10 vmlinuz-2.6.18-371.el5=> /mnt和/boot下的內容一樣 並且沒有進行格式化
mkisofs(鏡像檔案備份)
文法:mkisofs [-o鏡像檔案] [-rv] [-m file]待備份的檔案 [-V vol] –graft-point isodir=sysdir
選項與參數:
-o:鏡像檔案
-r:產生UNIX/Linux支援的檔案資料
-v:顯示構建ISO的過程
-m:排除的檔案
-V:卷標名稱
-graft-point:目錄對照名稱,如果不進行指定所以的資訊都會保持在根目錄
舉例:
[root@bogon ~]# mkisofs -o /tmp/system.img -r -m /home/lost+found -V 'tkf_file' -graft-point /root=/root /home=/home /etc=/etc[root@bogon ~]# mount -o loop /tmp/system.img /mnt[root@bogon ~]# ll /mntdr-xr-xr-x 114 root root 34816 03-01 14:31 etcdr-xr-xr-x 3 root root 2048 03-01 14:31 homedr-xr-xr-x 18 root root 4096 03-01 14:31 root