备份重于一切!所以今天重温了一下备份恢复。dump restore tar dd ,废话不多说,看少许的介绍及案例,你即可明白 。
dump
先摘点东西看看:
dump为备份工具程序,可将目录或整个文件系统备份至指定的设备,或备份成一个大文件。dump 可以执行类似 tar 的功能。然而,dump 倾向于考虑文件系统而不是个别的文件。下面是引自 dump 手册文件中的内容:“dump 检查 ext2 文件系统上的文件,并确定哪些文件需要备份。这些文件将出于安全保护而被复制到给定的磁盘、磁带或其他存储媒体上……大于输出媒体容量的转储将被划分到多个卷。在大多数媒体上,容量是通过一直写入直至返回一个 end-of-media 标记来确定的。”
看了man 页,参数太多,记不过来,就用其中的一点就OK了。
首先,我备份个别文件的时候,出错率高于备份文件系统。
以下是我模拟的一个案例,参考一下即可。有兴趣的可以求助于 man 页。呵呵
dd if=/dev/zero of=f5 bs=1024k count=100
losetup /dev/loop2 f5
blockdev --getsize /dev/loop2
mount /dev/loop2 /mnt/max/
mkfs.ext3 /dev/loop2
mount /dev/loop2 /mnt/max/
cp -r /tmp/max/* /mnt/max/
dump -0u -f /tmp/can/max.dmp /dev/loop2
下面来插播点广告,有点长。
使用dump命令时,它会建立一份自上次备份操作以来进行修改过的文件列表,然后把这些文件打包成一个单独的文件。在做备份时,需要指定一个备份级别,它是0-9之间的一个整数。级别为N的转储会对从上次进行的级别小于N的转储操作以来修改过的所有文件进行备份,而级别0就是完全备份。通过这种方式,可以很轻松的实现增量备份,差异备份,甚至每日备份。例如,第一次备份时可选择级别0(具体操作看后面),以后每天做增量备份时就可以每天依次使用级别1,级别2,级别3等等… …;当需要每天做差异备份时,可先选择级别0做完整备份,然后每天都使用同一大于0的级别就行了,比如说第二天用5,第三天也用5,第四天也一样。
使用dump的优点:
1,备份可以跨多卷磁带
2,能备份任何类型的文件,甚至是设备
3,备份时,文件的权限,宿主,宿组,修改时间等都会被保存
4,能够正确处理从未包含任何数据的文件块(孔洞文件)
5,能够做增量,差异备份
它也有不足:
1,每个文件系统必须单独转储备份
2,只有本地计算机的文件系统才能够转储备份(rdump,rrestore可用来弥补此项不足)
当然,使用tar也可以用来实现备份和还原,但tar只能在Linux或Unix环境下使用,对于跨平台的环境,dump使用起来个人感觉更方便一些。
如果有条件,dump也可以将备份存储在磁带上。Linux通常用/dev/st0代表倒带设备,而用/dev/nst0代表非倒带设备,使用倒带设备存储时,当磁带用完它会自动倒带并接着存储,所以会覆盖以前的数据,这样就存在以前数据丢失的风险。这个地方咱们就不详细讨论了。 |
[root@max can]# dump -0u -f /tmp/can/max.dmp /dev/loop2
DUMP: Date of this level 0 dump: Fri Feb 20 11:10:35 2009
DUMP: Dumping /dev/loop2 (/mnt/max) to /tmp/can/max.dmp
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 17573 blocks.
DUMP: Volume 1 started with block 1 at: Fri Feb 20 11:10:35 2009
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /tmp/can/max.dmp
DUMP: Volume 1 completed at: Fri Feb 20 11:10:35 2009
DUMP: Volume 1 17610 blocks (17.20MB)
DUMP: 17610 blocks (17.20MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 0 dump: Fri Feb 20 11:10:35 2009
DUMP: Date this dump completed: Fri Feb 20 11:10:35 2009
DUMP: Average transfer rate: 0 kB/s
DUMP: DUMP IS DONE
cp /mnt/hda1/max/collect/* /mnt/max/
[root@max can]# dump -1u -f /tmp/can/max1.dmp /dev/loop2
DUMP: Date of this level 1 dump: Fri Feb 20 11:14:52 2009
DUMP: Date of last level 0 dump: Fri Feb 20 11:10:35 2009
DUMP: Dumping /dev/loop2 (/mnt/max) to /tmp/can/max1.dmp
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 3562 blocks.
DUMP: Volume 1 started with block 1 at: Fri Feb 20 11:14:52 2009
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /tmp/can/max1.dmp
DUMP: Volume 1 completed at: Fri Feb 20 11:14:52 2009
DUMP: Volume 1 3560 blocks (3.48MB)
DUMP: 3560 blocks (3.48MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 1 dump: Fri Feb 20 11:14:52 2009
DUMP: Date this dump completed: Fri Feb 20 11:14:52 2009
DUMP: Average transfer rate: 0 kB/s
DUMP: DUMP IS DONE
[root@max can]# ll -h
总计 121M
-rw-r--r-- 1 root root 100M 02-20 11:08 f5
-rw-r--r-- 1 root root 3.5M 02-20 11:14 max1.dmp
-rw-r--r-- 1 root root 18M 02-20 11:10 max.dmp
[root@max can]# cat /etc/dumpdates
/dev/loop2 0 Fri Feb 20 11:10:35 2009 -0300
/dev/loop2 1 Fri Feb 20 11:14:52 2009 -0300
[root@max can]#
要查看其备份文件里的内容或恢复 就要用到 restore 命令
[root@max can]# restore -tf /tmp/can/max.dmp
Dump date: Fri Feb 20 11:10:35 2009
Dumped from: the epoch
Level 0 dump of /mnt/max on max.com:/dev/loop2
Label: none
2 .
11 ./lost+found
12 ./apache-tomcat-5.5.23.tar
5929 ./ftp.sh
5930 ./kdiag.sh
5931 ./logrotate.sh
。
。
[root@max can]# restore -tf /tmp/can/max2.dmp
restore: /tmp/can/max2.dmp: No such file or directory
[root@max can]# restore -tf /tmp/can/max1.dmp
Dump date: Fri Feb 20 11:14:52 2009
Dumped from: Fri Feb 20 11:10:35 2009
Level 1 dump of /mnt/max on max.com:/dev/loop2
Label: none
2 .
5942 ./atm_sar.tgz
5943 ./change-apache,ftp-to-windows
5944 ./change-character.txt
5945 ./change-tablespace.txt
5947 ./community-law.txt
5950 ./difference-hwadd-macaddr
5952 ./echo-color.txt
5953 ./emca-emctl.txt
5955 ./find.txt
5957 ./htt-https.txt
。
。
要全部恢复就要用到
[root@max can]# restore -rf max.dmp
[root@max can]# ls
apache-tomcat-5.5.23.tar kdiag.sh max1.dmp Oracle Database10g性能调整与优化.part1(2).rar restoresymtable unrm-0.92
f5 logrotate.sh max.dmp Oracle Database10g性能调整与优化.part1.rar sd unrm-0.92.tar.gz
ftp.sh lost+found mbr Oracle Database 11g DBA.rar top.log 汇总.rar
要恢复其中的一部分就要用到
[root@max can]# restore -if max1.dmp
restore > ls
atm_sar.tgz
change-apache,ftp-to-windows
change-character.txt
change-tablespace.txt
cluster.txt
community-law.txt
cpu-ratio.txt
dba-duty.txt
difference-hwadd-macaddr
dns.txt
echo-color.txt
emca-emctl.txt
emctl.txt
find.txt
restore-dir.txt
rman-back-format.txt
rman.txt
rsync.txt
sar.txt
screen.txt
tap1.txt
telnet-remote
tuxedo---ha.tar.bz2
two-clu-ha.txt
vmstat-iostat-sar.txt
vmware-all.cn
vmware.cn
vnc-xmanager.txt
restore > add vmware.cn
restore > extract
You have not read any volumes yet.
Unless you know which volume your file(s) are on you should start
with the last volume and work towards the first.
Specify next volume # (none if no more volumes): 1
set owner/mode for '.'? [yn] n
restore > quit
[root@max can]# ls
apache-tomcat-5.5.23.tar kdiag.sh max1.dmp Oracle Database10g性能调整与优化.part1(2).rar restoresymtable unrm-0.92 汇总.rar
f5 logrotate.sh max.dmp Oracle Database10g性能调整与优化.part1.rar sd unrm-0.92.tar.gz
ftp.sh lost+found mbr Oracle Database 11g DBA.rar top.log vmware.cn
[root@max can]#
要查看 restore 有哪些选项就用
[root@max can]# restore -if max1.dmp
restore > ?
Available commands are:
ls [arg] - list directory
cd arg - change directory
pwd - print current directory
add [arg] - add `arg' to list of files to be extracted
delete [arg] - delete `arg' from list of files to be extracted
extract - extract requested files
setmodes - set modes of requested directories
quit - immediately exit program
what - list dump header information
verbose - toggle verbose flag (useful with ``ls'')
prompt - toggle the prompt display
help or `?' - print this list
If no `arg' is supplied, the current directory is used
restore > quit
[root@max can]#
当然 还有很多功能,暂且不谈。