歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

dump和restore命令實現全備、增量備份和差異備份

dump和restore命令實現全備、增量備份和差異備份   差異備份,在全備的基礎上做備份。因為tar命令不能實現差異備份,所以本文講解如何用dump和restore命令實現。當然dump和restore命令也可以實現全備和增量備份。   一 創建備份目錄 分區 掛載 [plain]  [root@serv01 data]# mkdir /backup   [root@serv01 data]# fdisk /dev/sdb   [root@serv01 data]# fdisk /dev/sdc   [root@serv01 data]# mkfs.ext4 /dev/sdb1   [root@serv01 data]# mkfs.ext4 /dev/sdc1       [root@serv01 data]# mount /dev/sdb1 /data   [root@serv01 data]# mount /dev/sdc1/backup/     二 拷貝文件、修改配置文件 [plain]  #拷貝文件   [root@serv01 data]# rm -rf *   [root@serv01 data]# cp /boot/* .   cp: omitting directory `/boot/efi'   cp: omitting directory `/boot/grub'   cp: omitting directory `/boot/lost+found'   #向fstab文件追加內容   [root@serv01 data]# echo "/dev/sdb1/data ext4 defaults 1 2" >> /etc/fstab   [root@serv01 data]# echo "/dev/sdc1/backup ext4 defaults 1 2" >> /etc/fstab     三 dump和restore——實現全備 [plain]  [root@serv01 data]# yum install dump -y   #dump:支持增量備份和差異備份,只能對單獨的分區進行備份   #0:全備   #u:把/etc/dumpdates更新   #f:備份後的名字   [root@serv01 data]# cd /backup/   [root@serv01 backup]# ls   lost+found   [root@serv01 backup]# rm -rf lost+found/   #第一次查看,發現dumpdates沒有任何內容   [root@serv01 backup]# ls /etc/dumpdates   /etc/dumpdates   #備份   [root@serv01 backup]# dump -0uf data01.dump/data/    DUMP: Date of this level 0 dump: Fri Aug 2 18:57:53 2013    DUMP: Dumping /dev/sdb1 (/data) to data01.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 59 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 18:57:53 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data01.dump    DUMP: Volume 1 completed at: Fri Aug 2 18:57:53 2013    DUMP: Volume 1 50 blocks (0.05MB)    DUMP: 50 blocks (0.05MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 0 dump: Fri Aug 2 18:57:53 2013    DUMP: Date this dump completed: Fri Aug  2 18:57:53 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   [root@serv01 backup]# ll   total 52   -rw-r--r—. 1 root root 51200 Aug  2 18:57 data01.dump   #查看dumpdates文件,發現已經更新了   [root@serv01 backup]# cat /etc/dumpdates   /dev/sdb1 0 Fri Aug  2 18:57:53 2013 +0800       #還原,數據沒有了,重新備份   [root@serv01 backup]# cd /data   [root@serv01 data]# ls   lost+found   [root@serv01 data]# rm -rf *   [root@serv01 data]# cp /boot/* ./   cp: omitting directory `/boot/efi'   cp: omitting directory `/boot/grub'   cp: omitting directory `/boot/lost+found'   [root@serv01 data]# cd /backup/   [root@serv01 backup]# ls   data01.dump   [root@serv01 backup]# rm -rf *   [root@serv01 backup]# ls   [root@serv01 backup]# > /etc/dumpdates   [root@serv01 backup]# dump -0uf dump01.dump/data/    DUMP: Date of this level 0 dump: Fri Aug 2 19:02:20 2013    DUMP: Dumping /dev/sdb1 (/data) to dump01.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 18674 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 19:02:20 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing dump01.dump    DUMP: Volume 1 completed at: Fri Aug 2 19:02:20 2013    DUMP: Volume 1 18670 blocks (18.23MB)    DUMP: 18670 blocks (18.23MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 0 dump: Fri Aug 2 19:02:20 2013    DUMP: Date this dump completed: Fri Aug  2 19:02:20 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   #進入data目錄,發現有數據   [root@serv01 backup]# cd /data   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         symvers-2.6.32-131.0.15.el6.x86_64.gz  vmlinuz-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  System.map-2.6.32-131.0.15.el6.x86_64   #全部刪除,模擬數據丟失   [root@serv01 data]# rm -rf *   [root@serv01 data]# ls   #恢復數據   [root@serv01 data]# restore -rf/backup/dump01.dump   #恢復成功   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         restoresymtable                       System.map-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  symvers-2.6.32-131.0.15.el6.x86_64.gz  vmlinuz-2.6.32-131.0.15.el6.x86_64       [root@serv01 data]# cp /etc/passwd ./   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         passwd          symvers-2.6.32-131.0.15.el6.x86_64.gz vmlinuz-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  restoresymtable  System.map-2.6.32-131.0.15.el6.x86_64   [root@serv01 data]# cd /backup/     四 dump和restore——實現增量備份 [plain]  #增量備份:1-9   #dump:備份磁盤上的塊,不止是文件;只能備份單獨的分區       [root@serv01 data]# rm -rf *   [root@serv01 data]# cp /boot/* .   cp: omitting directory `/boot/efi'   cp: omitting directory `/boot/grub'   cp: omitting directory `/boot/lost+found'   [root@serv01 data]# cd /backup/   [root@serv01 backup]# ll   total 18672   -rw-r--r--. 1 root root 19118080 Aug  2  2013dump01.dump   [root@serv01 backup]# rm -rf dump01.dump       #第一次備份:全備   [root@serv01 backup]# dump -0uf data01.dump/data/    DUMP: Date of this level 0 dump: Fri Aug 2 11:25:57 2013    DUMP: Dumping /dev/sdb1 (/data) to data01.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 18674 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:25:57 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data01.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:25:57 2013    DUMP: Volume 1 18670 blocks (18.23MB)    DUMP: 18670 blocks (18.23MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 0 dump: Fri Aug 2 11:25:57 2013    DUMP: Date this dump completed: Fri Aug  2 11:25:57 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   [root@serv01 backup]# ll   total 18672   -rw-r—r—. 1 root root 19118080 Aug  2 11:25 data01.dump   #拷貝文件到data目錄   #第二次備份:增量備份   [root@serv01 backup]# cp /etc/inittab/data/   [root@serv01 backup]# dump -1uf data02.dump/data/    DUMP: Date of this level 1 dump: Fri Aug 2 11:26:28 2013    DUMP: Date of last level 0 dump: Fri Aug 2 11:25:57 2013    DUMP: Dumping /dev/sdb1 (/data) to data02.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 55 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:26:28 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data02.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:26:28 2013    DUMP: Volume 1 50 blocks (0.05MB)    DUMP: 50 blocks (0.05MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 1 dump: Fri Aug 2 11:26:28 2013    DUMP: Date this dump completed: Fri Aug  2 11:26:28 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   [root@serv01 backup]# ll   total 18724   -rw-r--r--. 1 root root 19118080 Aug  2 11:25 data01.dump   -rw-r--r—. 1 root root    51200 Aug 2 11:26 data02.dump   #再次拷貝文件   [root@serv01 backup]# cp /etc/passwd /data/   #第三次備份:增量備份   [root@serv01 backup]# dump -2uf data03.dump/data/    DUMP: Date of this level 2 dump: Fri Aug 2 11:27:07 2013    DUMP: Date of last level 1 dump: Fri Aug 2 11:26:28 2013    DUMP: Dumping /dev/sdb1 (/data) to data03.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 55 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:27:07 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data03.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:27:07 2013    DUMP: Volume 1 50 blocks (0.05MB)    DUMP: 50 blocks (0.05MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 2 dump: Fri Aug 2 11:27:07 2013    DUMP: Date this dump completed: Fri Aug  2 11:27:07 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   [root@serv01 backup]# cat /etc/dumpdates   /dev/sdb1 0 Fri Aug  2 11:25:57 2013 +0800   /dev/sdb1 1 Fri Aug  2 11:26:28 2013 +0800   /dev/sdb1 2 Fri Aug  2 11:27:07 2013 +0800   #第四次備份:增量備份   [root@serv01 backup]# dump -3uf data04.dump/data/    DUMP: Date of this level 3 dump: Fri Aug 2 11:28:48 2013    DUMP: Date of last level 2 dump: Fri Aug 2 11:27:07 2013    DUMP: Dumping /dev/sdb1 (/data) to data04.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 50 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:28:48 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data04.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:28:48 2013    DUMP: Volume 1 40 blocks (0.04MB)    DUMP: 40 blocks (0.04MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 3 dump: Fri Aug 2 11:28:48 2013    DUMP: Date this dump completed: Fri Aug  2 11:28:48 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   [root@serv01 backup]# cat /etc/dumpdates   /dev/sdb1 0 Fri Aug  2 11:25:57 2013 +0800   /dev/sdb1 1 Fri Aug  2 11:26:28 2013 +0800   /dev/sdb1 2 Fri Aug  2 11:27:07 2013 +0800   /dev/sdb1 3 Fri Aug  2 11:28:48 2013 +0800   #進入data目錄,模擬數據丟失   [root@serv01 backup]# cd /data   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         inittab  symvers-2.6.32-131.0.15.el6.x86_64.gz   initramfs-2.6.32-131.0.15.el6.x86_64.img  passwd  vmlinuz-2.6.32-131.0.15.el6.x86_64   [root@serv01 data]# rm -rf *   [root@serv01 data]# ls   #恢復數據:一級一級地恢復   [root@serv01 data]# restore -rf/backup/data01.dump   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         restoresymtable                        System.map-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  symvers-2.6.32-131.0.15.el6.x86_64.gz  vmlinuz-2.6.32-131.0.15.el6.x86_64   [root@serv01 data]# restore -rf/backup/data03.dump   restore: Incremental tape too low   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         restoresymtable                       System.map-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  symvers-2.6.32-131.0.15.el6.x86_64.gz  vmlinuz-2.6.32-131.0.15.el6.x86_64   [root@serv01 data]# restore -rf/backup/data02.dump   [root@serv01 data]# restore -rf/backup/data03.dump   [root@serv01 data]# restore -rf/backup/data04.dump   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         inittab  restoresymtable                        vmlinuz-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  passwd  symvers-2.6.32-131.0.15.el6.x86_64.gz       #恢復時報錯:   #1.恢復的數據不對:查看掛載是否正確   #2.restore: Incremental tape too high 同一級別的備份了多次,所以會報這個錯誤,檢查/etc/dumpdates文件和拼寫是否錯誤     五 dump和restore——實現差異備份 [plain]  #演示差異備份   [root@serv01 data]# cd /backup/   [root@serv01 backup]# rm -rf *   [root@serv01 backup]# rm -rf data01.dump   [root@serv01 backup]# > /etc/dumpdates   #首先全備   [root@serv01 backup]# dump -0uf data01.dump/data/    DUMP: Date of this level 0 dump: Fri Aug 2 11:43:51 2013    DUMP: Dumping /dev/sdb1 (/data) to data01.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 16672 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:43:51 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data01.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:43:51 2013    DUMP: Volume 1 16680 blocks (16.29MB)    DUMP: 16680 blocks (16.29MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 0 dump: Fri Aug 2 11:43:51 2013    DUMP: Date this dump completed: Fri Aug  2 11:43:51 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   [root@serv01 backup]# cat /etc/dumpdates   /dev/sdb1 0 Fri Aug  2 11:43:51 2013 +0800   #拷貝fstab文件   [root@serv01 backup]# cp /etc/fstab /data/   #差異備份   [root@serv01 backup]# dump -1uf data02.dump/data/    DUMP: Date of this level 1 dump: Fri Aug 2 11:44:20 2013    DUMP: Date of last level 0 dump: Fri Aug 2 11:43:51 2013    DUMP: Dumping /dev/sdb1 (/data) to data02.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 55 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:44:20 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data02.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:44:20 2013    DUMP: Volume 1 50 blocks (0.05MB)    DUMP: 50 blocks (0.05MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 1 dump: Fri Aug 2 11:44:20 2013    DUMP: Date this dump completed: Fri Aug  2 11:44:20 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   #拷貝yum.conf文件   [root@serv01 backup]# cp /etc/yum.conf/data   [root@serv01 backup]# dump -1ufdata021.dump /data/    DUMP: Date of this level 1 dump: Fri Aug 2 11:44:47 2013    DUMP: Date of last level 0 dump: Fri Aug 2 11:43:51 2013    DUMP: Dumping /dev/sdb1 (/data) to data021.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 60 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:44:47 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data021.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:44:47 2013    DUMP: Volume 1 60 blocks (0.06MB)    DUMP: 60 blocks (0.06MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 1 dump: Fri Aug 2 11:44:47 2013    DUMP: Date this dump completed: Fri Aug  2 11:44:47 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE   #拷貝文件,然後差異備份   [root@serv01 backup]# cp /etc/networks/data   [root@serv01 backup]# dump -1ufdata0211.dump /data/    DUMP: Date of this level 1 dump: Fri Aug 2 11:45:34 2013    DUMP: Date of last level 0 dump: Fri Aug 2 11:43:51 2013    DUMP: Dumping /dev/sdb1 (/data) to data0211.dump    DUMP: Label: none    DUMP: Writing 10 Kilobyte records    DUMP: mapping (Pass I) [regular files]    DUMP: mapping (Pass II) [directories]    DUMP: estimated 65 blocks.    DUMP: Volume 1 started with block 1 at: Fri Aug  2 11:45:34 2013    DUMP: dumping (Pass III) [directories]    DUMP: dumping (Pass IV) [regular files]    DUMP: Closing data0211.dump    DUMP: Volume 1 completed at: Fri Aug 2 11:45:34 2013    DUMP: Volume 1 70 blocks (0.07MB)    DUMP: 70 blocks (0.07MB) on 1 volume(s)    DUMP: finished in less than a second    DUMP: Date of this level 1 dump: Fri Aug 2 11:45:34 2013    DUMP: Date this dump completed: Fri Aug  2 11:45:34 2013    DUMP: Average transfer rate: 0 kB/s    DUMP: DUMP IS DONE       #模擬數據刪除   [root@serv01 backup]# cd /data   [root@serv01 data]# rm -rf *   #恢復時需要有全備的文件和想恢復的文件(或者最後一次),只需要兩個   [root@serv01 data]# restore -rf/backup/data01.dump   [root@serv01 data]# restore -rf/backup/data021.dump   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         inittab          symvers-2.6.32-131.0.15.el6.x86_64.gz   fstab                                    passwd           vmlinuz-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  restoresymtable  yum.conf   [root@serv01 data]# rm -rf *   [root@serv01 data]# restore -rf/backup/data01.dump   [root@serv01 data]# restore -rf/backup/data0211.dump   [root@serv01 data]# ls   config-2.6.32-131.0.15.el6.x86_64         inittab   restoresymtable                        yum.conf   fstab                                    networks symvers-2.6.32-131.0.15.el6.x86_64.gz   initramfs-2.6.32-131.0.15.el6.x86_64.img  passwd   vmlinuz-2.6.32-131.0.15.el6.x86_64       #差異備份:一定是在全備的基礎上       #dd沒有增量備份的功能   #磁盤拷貝(對拷)   [root@serv01 backup]# cd /data/   [root@serv01 data]# ls   [root@serv01 data]# cp /boot/* .   cp: omitting directory `/boot/efi'   cp: omitting directory `/boot/grub'   cp: omitting directory `/boot/lost+found'   [root@serv01 data]# dd if=/dev/sdb1of=/dev/sdc1   dd: writing to `/dev/sdc1': Input/outputerror   4192897+0 records in   4192896+0 records out   2146762752 bytes (2.1 GB) copied, 71.3082s, 30.1 MB/s   [root@serv01 data]# df -h   Filesystem            Size Used Avail Use% Mounted on   /dev/sda2             9.7G  1.1G 8.1G  12% /   tmpfs                 188M     0 188M   0% /dev/shm   /dev/sda1             194M   25M 160M  14% /boot   /dev/sda5             4.0G  137M 3.7G   4% /opt   /dev/sr0              3.4G 3.4G     0 100% /iso   /dev/sdb1             2.0G   54M 1.9G   3% /data   /dev/sdc1             2.0G   35M 1.9G   2% /backup   [root@serv01 data]# ls /backup/   config-2.6.32-131.0.15.el6.x86_64        symvers-2.6.32-131.0.15.el6.x86_64.gz vmlinuz-2.6.32-131.0.15.el6.x86_64   initramfs-2.6.32-131.0.15.el6.x86_64.img  System.map-2.6.32-131.0.15.el6.x86_64    
Copyright © Linux教程網 All Rights Reserved