Linux系统学习第四章:文件压缩、打包与备份(二)备份与还原

一、备份:dump

  (1)dump -S  设备名 :显示需要备份的设备所在分区所需要的最小的容量

1 [root@localhost php]# dump -S /dev/sda2
2 4710404096

  (2)dump -W 查看所有分区是否备份过(或者说在/etc/fstab这个文件中 是否有相应的备份的记录)

1 [root@localhost php]# dump -W
2 Last dump(s) done (Dump '>' file systems):
3 > /dev/sda2     (     /) Last dump: never
4 > /dev/sda3     ( /home) Last dump: never
5 > /dev/sda1     ( /boot) Last dump: never

  (3) dump [-uvj] [-level] [-f] 备份后的文件名 要备份的数据

  参数说明:

    -u 将备份的时间记录到/etc/dumpdates文件中

    -v 显示备份进度

    -j 使用bzip2进行压缩

    -level 用0-9代替这个level代表备份的等级

    -f 后面接备份的文件名

 1 [root@localhost php]# dump -0uvj -f /root/home_20121205.dump /home
 2   DUMP: Date of this level 0 dump: Wed Dec  5 15:51:14 2012
 3   DUMP: Dumping /dev/sda3 (/home) to /root/home_20121205.dump
 4   DUMP: Excluding inode 8 (journal inode) from dump
 5   DUMP: Excluding inode 7 (resize inode) from dump
 6   ……(#此处省略备份过程中的相关数据)
 7   DUMP: DUMP IS DONE
 8 [root@localhost php]# cd /root
 9 [root@localhost ~]# ls
10 anaconda-ks.cfg  Desktop  home_20121205.dump  install.log  install.log.syslog

  我们再来测试一下 dump -W这个命令查看一下:

1 [root@localhost ~]# dump -W 
2 Last dump(s) done (Dump '>' file systems):
3 > /dev/sda2     (     /) Last dump: never
4   /dev/sda3     ( /home) Last dump: Level 0, Date Wed Dec  5 15:51:14 2012
5 > /dev/sda1     ( /boot) Last dump: never

    因为刚才备份过一次了,所以就有相应的记录了

二、还原:restore

  (1)restore -t -f 备份文件

    查看备份文件的相关信息

 1 [root@localhost ~]# restore -t -f home_20121205.dump 
 2 Dump tape is compressed.
 3 Dump   date: Wed Dec  5 15:51:14 2012
 4 Dumped from: the epoch
 5 Level 0 dump of /home on localhost.localdomain:/dev/sda3
 6 Label: /home
 7          2      .
 8         11      ./lost+found
 9      32001      ./admin
10     ……(此处省略其他文件)

  (2)restore -C -f 备份文件

 查看备份文件与备份所在的目录的现状的差异

1 [root@localhost ~]# restore -C -f home_20121205.dump 
2 Dump   date: Wed Dec  5 16:04:53 2012
3 Dumped from: the epoch
4 Level 0 dump of /home on localhost.localdomain:/dev/sda3
5 Label: /home
6 filesys = /home

  (3)restore -i -f 备份文件

  进入互动模式

  用help调出所有互动模式下可以使用的命令:

 1 [root@localhost ~]# restore -i -f home_20121205.dump 
 2 restore > help
 3 Available commands are:
 4         ls [arg] - list directory
 5         cd arg - change directory
 6         pwd - print current directory
 7         add [arg] - add `arg' to list of files to be extracted
 8         delete [arg] - delete `arg' from list of files to be extracted
 9         extract - extract requested files
10         setmodes - set modes of requested directories
11         quit - immediately exit program
12         what - list dump header information
13         verbose - toggle verbose flag (useful with ``ls'')
14         prompt - toggle the prompt display
15         help or `?' - print this list
16 If no `arg' is supplied, the current directory is used
17 restore > ls
18 .:
19 admin/      dev/        ec_admin/   lost+found/ test/

  (4)restore -r -f 备份文件

  还原整个文件系统:

1 [root@localhost ~]# restore -r -f home_20121205.dump 
2 restore: ./lost+found: File exists
3 restore: ./admin: File exists
4 restore: ./admin/.mozilla: File exists
5 restore: ./admin/.mozilla/extensions: File exists
6 restore: ./admin/.mozilla/plugins: File exists
7 restore: ./admin/.kde: File exists
8 restore: ./admin/.kde/Autostart: File exists
9 ……(省略其他文件)

三、备份文件或磁盘:dd

  语法:dd if=被备份的文件 of=备份文件 bs=block块大小 count=block数量

  

1 [root@localhost ~]# dd if=/etc/passwd of=/home/passwd
2 3+1 records in
3 3+1 records out
4 2028 bytes (2.0 kB) copied, 0.000217227 seconds, 9.3 MB/s
5 [root@localhost ~]# cd /home/
6 [root@localhost home]# ls
7 360  admin  dev  ec_admin  lost+found  passwd  test

 

转载于:https://www.cnblogs.com/withec/archive/2012/12/05/2803425.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值