首页 > 代码库 > dump备份及还原
dump备份及还原
完整备份工具dump及restore还原
备份整个文件系统
备份目录
dump备份
原理:通过指定level来实现完整备份和差异备份,第一次备份时使用的是level0,即完整备份,第二次备份时,指定level1,和level0比较只备份有差异的部分
备份文件系统
单一的文件系统可以使用完整的dump功能,包括使用全部0~9level,也可以使用挂载点或设备名来备份(如:/dev/sda1)
备份目录
如仅备份/home/pyz,而非独立文件系统,此时备份有限制:
1.所有备份数据必须要在该目录下
2.仅能使用level0,即仅支持完整备份
3.不支持-u选项,即不能建立/etc/dumpdates文件来记录各level备份的时间
用法:
[root@instructor~]#dump [-Suvj] [-level] [-f 备份文件名] 等待备份文件
参数:
-S:显示待备份文件需要占用的磁盘空间
-u:将这次dump的时间记录到/etc/dumpdates文件中
-v:显示详细的备份过程
-j:将备份文件使用bzip2压缩,默认压缩等级为2
-level:备份级别,0~9
-f:后接备份后的文件名
例:备份系统中最小的文件系统
1.先找出系统中最小的文件系统
[root@instructor ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_instructor-lv_root 7.5G 6.9G 486M 94% / tmpfs 504M 112K 504M 1% /dev/shm /dev/sda1 485M 32M 428M 7% /boot /dev/sdb1 485M 11M 449M 3% /mnt/new /dev/sdb2 97M 16M 77M 17% /mnt/test
这里最小的就是/dev/sdb2
2.测试一下,备份/dev/sdb2需要多大空间
[root@instructor ~]# dump -S /dev/sdb2 10537984 //大概需要10M左右
3.将/dev/sdb2完整备份到/tmp/test下,命名为test.dump,同时更新记录文件
[root@instructor test]# dump -0u -f/tmp/test/test.dump /mnt/test DUMP: Date of this level 0 dump: Wed Oct 8 11:20:08 2014 //记录等级与备份时间 DUMP: Dumping /dev/sdb2 (/mnt/test) to /tmp/test/test.dump //来源与目标 DUMP: Label: test DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 10291 blocks. DUMP: Volume 1 started with block 1 at: Wed Oct 8 11:20:08 2014 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /tmp/test/test.dump DUMP: Volume 1 completed at: Wed Oct 8 11:20:08 2014 DUMP: Volume 1 10310 blocks (10.07MB) DUMP: 10310 blocks (10.07MB) on 1 volume(s) DUMP:finished in less than a second DUMP: Date of this level 0 dump: Wed Oct 8 11:20:08 2014 DUMP: Date this dump completed: Wed Oct 8 11:20:08 2014 DUMP: Average transfer rate: 0 kB/s DUMP: DUMP IS DONE
4.查看系统中建立的记录
[root@instructor test]# cat /etc/dumpdates /dev/sdb2 0 Wed Oct 8 11:20:08 2014 +0800
查看被dump过的文件系统
[root@instructor test]# dump -W Last dump(s) done (Dump ‘>‘ filesystems): > /dev/mapper/vg_instructor-lv_root ( /) Last dump: never > /dev/sda1 ( /boot) Last dump: never /dev/sdb1 (/mnt/new) Lastdump: never /dev/sdb2 (/mnt/test) Lastdump: Level 0, Date Wed Oct 8 11:20:082014
显示/dev/sdb2备份过
例:差异备份
1.在/dev/sdb2即/mnt/test中创建一个约10M的文件
[root@instructor test]# dd if=/dev/zeroof=/mnt/test/testing.img bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB) copied, 0.0893004 s,117 MB/s
2.开始差异备份
[root@instructor test]# dump -1u -f/tmp/test/test.dump.1 /mnt/test DUMP: Date of this level 1 dump: Wed Oct 8 11:31:13 2014 DUMP: Date of last level 0 dump: Wed Oct 8 11:20:08 2014 DUMP: Dumping /dev/sdb2 (/mnt/test) to /tmp/test/test.dump.1 DUMP: Label: test DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 10283 blocks. DUMP: Volume 1 started with block 1 at: Wed Oct 8 11:31:13 2014 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /tmp/test/test.dump.1 DUMP: Volume 1 completed at: Wed Oct 8 11:31:13 2014 DUMP: Volume 1 10300 blocks (10.06MB) DUMP: 10300 blocks (10.06MB) on 1 volume(s) DUMP: finished in less than a second DUMP: Date of this level 1 dump: Wed Oct 8 11:31:13 2014 DUMP: Date this dump completed: Wed Oct 8 11:31:13 2014 DUMP: Average transfer rate: 0 kB/s DUMP: DUMP IS DONE
3.查看是否有level1的记录
[root@instructor test]# cat /etc/dumpdates /dev/sdb2 0 Wed Oct 8 11:20:08 2014 +0800 /dev/sdb2 1 Wed Oct 8 11:31:13 2014 +0800
例:用dump备份目录(非文件系统),并且压缩
[root@instructor test]# dump -0j -f/tmp/test/etc.dump.bz2 /etc DUMP: Date of this level 0 dump: Wed Oct 8 11:50:16 2014 DUMP: Dumping /dev/mapper/vg_instructor-lv_root (/ (dir etc)) to/tmp/test/etc.dump.bz2 DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP:Compressing output at compression level 2 (bzlib) DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 75521 blocks. DUMP: Volume 1 started with block 1 at: Wed Oct 8 11:50:18 2014 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /tmp/test/etc.dump.bz2 DUMP: Volume 1 completed at: Wed Oct 8 11:51:11 2014 DUMP: Volume 1 took 0:00:53 DUMP: Volume 1 transfer rate: 424 kB/s DUMP: Volume 1 86570kB uncompressed, 22492kB compressed, 3.849:1 DUMP: 86570 blocks (84.54MB) on 1 volume(s) DUMP: finished in 53 seconds, throughput 1633 kBytes/sec DUMP: Date of this level 0 dump: Wed Oct 8 11:50:16 2014 DUMP: Date this dump completed: Wed Oct 8 11:51:11 2014 DUMP: Average transfer rate: 424 kB/s DUMP: Wrote 86570kB uncompressed, 22492kB compressed, 3.849:1 DUMP: DUMP IS DONE
dump默认不包含压缩功能,加了-j参数后可以使用bzip2进行压缩
restore还原
用法:
[root@instructortest]# restore -t [-f dumpfile] [-h] 查看dump文件 [root@instructor test]# restore -C [-fdumpfile] [-D 挂载点] 比较dump与原文件 [root@instructor test]# restore -i [-fdumpfile] 互动模式 [root@instructor test]# restore -r [-fdumpfile] 还原整个文件系统
参数:
-t:查看dump备份文件内容
-C:dump后的文件和原文件作对比
-i:互动模式,可以仅还原部分文件,用于还原备份目录的文件
-r:还原整个文件系统
-h:查看完整备份中的inode与文件系统label信息
-f:后面跟要处理的dump文件
-D:与-C进行搭配,可以查出后面挂载点与原文件的区别
例:用restore查看dump后的备份数据
[root@instructor test]# restore -t -f/tmp/test/etc.dump.bz2
比较备份文件与原文件的差异
[root@instructor test]# cd /mnt/test [root@instructor test]# mv testing.imgtesting.img.bak [root@instructor test]# restore -C -f/tmp/test/test.dump.1 Dump date: Wed Oct 8 11:31:13 2014 Dumped from: Wed Oct 8 11:20:08 2014 Level 1 dump of /mnt/test oninstructor:/dev/sdb2 Label: test filesys = /mnt/test restore:unable to stat ./testing.img: No such file or directory Somefiles were modified! 1 compare errors
还原整个文件系统
前提:先新建文件系统并将其挂载,然后进入到挂载点下面执行
[root@instructor test]# restore -r -f/tmp/test/test.dump
如果继续还原level1,则
[root@instructor test]# restore -r -f/tmp/test/test.dump.1
dump备份及还原