新聞中心

restore 命令的基本格式如下:
[root@localhost ~]# restore [模式選項(xiàng)] [-f]
此命令中,-f 選項(xiàng)用于指定備份文件的文件名;restore 命令常用的模式有以下 4 種,這 4 種模式不能混用:
- -C:比較備份數(shù)據(jù)和實(shí)際數(shù)據(jù)的變化。如果實(shí)際數(shù)據(jù)中的現(xiàn)有數(shù)據(jù)發(fā)生了變化,那么這個(gè)選項(xiàng)能夠檢測(cè)到這個(gè)變化。但是如果實(shí)際數(shù)據(jù)中新增了數(shù)據(jù),那么這個(gè)選項(xiàng)是不能檢測(cè)到變化的。舉個(gè)例子:別人給我了 100 萬元投資(實(shí)際數(shù)據(jù)),但是他有一個(gè)投資的賬本(備份數(shù)據(jù)),他要時(shí)不時(shí)地比對(duì)賬本和實(shí)際的 100 萬元投資,如果 100 萬元減少則馬上就能發(fā)現(xiàn)改變;但是如果投資增加,則不會(huì)報(bào)警;
- -i:進(jìn)入交互模式,手工選擇需要恢復(fù)的文件;
- -t:查看模式,用于查看備份文件中擁有哪些數(shù)據(jù);
- -r:還原模式,用于數(shù)據(jù)還原;
【例 1】比較備份數(shù)據(jù)和實(shí)際數(shù)據(jù)的變化。
這里大家需要注意,數(shù)據(jù)比較只有在原有數(shù)據(jù)減少或發(fā)生變化時(shí)才能檢測(cè)到變化,而新增的數(shù)據(jù)是不會(huì)被檢測(cè)到的。命令如下:
[root@localhost ~]# touch /boot/abc
#在/boot/目錄中新建abc文件
[root@localhost ~]# restore -C -f /root/boot.bak.bz2
Dump tape is compressed.
Dump date:Wed Jun 5 08:20:02 2013
Dumped from:the epoch
Level 0 dump of /boot on localhost:/dev/sda1
Label:none
filesys = /boot
#restore檢測(cè),沒有發(fā)現(xiàn)任何變化(當(dāng)然,因?yàn)閭浞輸?shù)據(jù)在備份時(shí)沒有abc文件,所以restore命令是不能識(shí)別新建文件的)
[root@localhost ~]# mv /boot/vmlinuz-2.6.32-279.el6.i686 /boot/vmlinuz-2.6.32-279.el6.i686.bak
#把/boot/目錄中的內(nèi)核鏡像文件改一個(gè)名字
[root@localhost ~]# restore -C -f /root/boot.bak.bz2
Dump tape is compressed.
Dump date:Wed Jun 5 08:20:02 2013
Dumped from:the epoch
Level 0 dump of /boot on localhost:/dev/sda1
Label:none
filesys = /boot
restore:unable to stat ./vmlinuz-2.6.32-279.el6.i686:No such file or directory Some files were modified! 1 compare errors
#restore發(fā)現(xiàn)內(nèi)核鏡像文件丟失
這個(gè)實(shí)驗(yàn)比較危險(xiǎn),一定要記得把內(nèi)核鏡像文件的名字改回來,否則一旦重啟,系統(tǒng)就會(huì)無法正常啟動(dòng)。
[root@localhost ~]# mv /boot/vmlinuz-2.6.32-279.el6.i686.bak /boot/vmlinuz2.6.32-279.el6.i686
【例 2】查看模式。
這種模式比較簡單,就是查看備份文件中到底包含什么內(nèi)容。命令如下:
[root@localhost ~]# restore -t -f boot.bak.bz2
Dump tape is compressed.
#備份數(shù)據(jù)是壓縮的
Dump date:Wed Jun 5 08:20:02 2013
#數(shù)據(jù)備份時(shí)間
Dumped from:the epoch
Level 0 dump of /boot on localhost:/dev/sda1
#備份等級(jí)
Label:none
#分區(qū)的卷標(biāo),沒有設(shè)定卷標(biāo)
2.
11 ./lost+found
12 ./grub
24 ./grub/grub.conf
13 ./grub/splash.xpm.gz
…省略部分輸出…
【例 3】還原模式
restore 命令的還原模式既可以用于還原整個(gè)分區(qū),也可以用于還原文件或目錄。命令格式是一樣的,不過要注意,如果要還原增量備份的數(shù)據(jù),則一定要先還原完全備份的數(shù)據(jù)。命令如下:
#還原boot.bak.bz2分區(qū)備份
#先還原完全備份的數(shù)據(jù)
[root@localhost ~]# mkdir boot.test
#建立準(zhǔn)備解壓縮的目錄。當(dāng)然,如果這個(gè)目錄是我新建的分區(qū),就可以直接把數(shù)據(jù)恢復(fù)到分區(qū)中
[root@localhost ~]# cd boot.test/
#進(jìn)入解壓縮目錄
[root@localhost boot.test]# restore -r -f /root/boot.bak.bz2
Dump tape is compressed.
#備份數(shù)據(jù)是壓縮數(shù)據(jù)
#解壓縮
[root@localhost boot.test]#ll
#查看一下解壓縮的文件
總用量21300
-rw-r--r--. 1 root root 106611 6月 22 2012 config-2.6.32-279.el6.i686 drwxr-xr-x. 3 root root 4096 4 月 10 21:47 efi drwxr-xr-x. 2 root root 4096 4 月 10 21:49 grub
-rw-r--r--. 1 root root 14708399 4 月 10 21:49 initrara£s-2.6.32-279.el6.i686.img
drwx------. 2 root root 4096 4 月 10 21:44 lost+found
-rw-------. 1 root root 47504 6 月 5 09:44 restoresymtable
-rw-r--r--. 1 root root 175903 6 月 22 2012 symvers-2.6.32-279.el6.i686.gz
-rw-r--r--. 1 root root 1846041 6 月 22 2012 System.map-2.6.32-279.el6.i686
-rw-r--r--. 1 root root 1048576 6 月 5 02:38 test
-rwxr-xr-x. 1 root root 3856608 6 月 22 2012 vmlinuz-2.6.32-279.el6.i686
#再還原增量備份的數(shù)據(jù)
[root@localhost boot.test]# restore -r -f /root/boot.bakl.bz2
Dump tape is compressed.
#恢復(fù)增量備份的數(shù)據(jù)
[root@localhost boot.test]# ll
總用量21328
-rw-r--r--. 1 root root 106611 6 月 22 2012 config-2.6.32-279.el6.i686
drwxr-xr-x. 3 root root 4096 4 月 10 21:47 efi
drwxr-xr-x. 2 root root 4096 4 月 10 21:49 grub
-rw-r--r--. 1 root root 14708399 4 月 10 21:49 initramfs-2.6.32-279.eX6.i686.img
-rw-r--r--. 1 root root 24772 6 月 5 08:20 install. log
#增量備份的install.log文件被恢復(fù)了
drwx------. 2 root root 4096 4 月 10 21:44 lost+found
-rw-------. 1 root root 47552 6 月 5 09:57 restoresymtable
-rw-r--r--. 1 root root 175903 6 月 22 2012 symvers-2.6.32-279.el6.i686.gz
-rw-r--r--. 1 root root 1846041 6 月 22 2012 System.map-2.6.32-279.el6.i686
-rw-r--r--. 1 root root 1048576 6 月 5 02:38 test
-rwxr-xr-x. 1 root root 3856608 6月 22 2012 vmlinuz-2.6.32-279.el6.i686
我們?cè)賮磉€原/etc/目錄的備份etc.dump.bz2,其實(shí)還原的方法是完全一樣的。命令如下:
[root@localhost ~]# restore -r -f etc.dump.bz2
Dump tape is compressed.
#還原etc.dump.bz2備份
[root@localhost ~]# ll -d /root/etc
drwxr-xr-x.103 root root 12288 6月 5 07:45 /root/etc
#在root下生成了etc目錄,里面的數(shù)據(jù)和/etc/目錄中的數(shù)據(jù)完全一致
當(dāng)前標(biāo)題:Linuxrestore命令:還原dump操作備份下的文件、目錄或分區(qū)
地址分享:http://fisionsoft.com.cn/article/cddeihd.html


咨詢
建站咨詢
