linux备份与恢复

 

一、备份

 

1、 备份概述

  • 完全备份
  • 所谓完全备份,指的是系统进行完整的数据备份
  • 优点:恢复一次备份文件即可
  • 缺点:备份的数据大,耗费时间长
  • 增量备份
  • 所谓增量备份,指的是在系统进行完第一次完整备份后,经过一段时间的运行,比较系统与备份文件之间的差异,仅备份有差异的文件而已。而第二次增量备份则是与第一次增量备份的数据比较,也是仅备份有差异的数据而已。
  • 优点:备份数据小且快速,效率高。
  • 缺点:恢复时需要多个备份文件经多次恢复。
  • 差异备份
  • 所谓差异备份,就是在第一次完整备份以后,以后的每一次备份都将于完整备份的不同之处备份。
  • 优点:恢复数据只需要第一次的完整备份和当前的差异备份即可,恢复速度快。
  • 缺点:备份的数据会随着时间越来越大。

 

 2、备份命令

dump [Suvj] [-level] [-f 备份文件]   待备份数据

常见参数:

-level 0-9,备份等级,0表示最完整备份,指定0以上的等级,则为增量备份;

-f 文件名   指定那个备份之后的文件名

-S  仅列出后面待备份数据需要多少磁盘空间可以备份完毕;

-u  将这次dump的时间记录到/etc/dumpdares文件中;

-v  将dump的文件过程显示出来;

-j  加入bzip2的支持!将数据进行压缩,默认bzip2的压缩等级为2;

-W  列出在/etc/fstab里面的具有dump设置的分区是否有备份过;

 

3、备份实例

1、查询磁盘空间,找容量较小的boot分区进行测试

[root@localhost /]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2       4.7G  555M  3.9G  13% /

tmpfs           931M     0  931M   0% /dev/shm

/dev/sda1       190M   27M  154M  15% /boot

/dev/sda3       4.7G  9.9M  4.5G   1% /data

/dev/sda7       5.5G  806M  4.4G  16% /usr

/dev/sda5       3.8G   99M  3.5G   3% /var

2、第一次等级0完全备份/boot分区并压缩

 [root@localhost /]# dump  -0uj  -f /root/boot.bak.bz2  /boot/

  DUMP: Date of this level 0 dump: Mon Aug  6 15:48:07 2018

  DUMP: Dumping /dev/sda1 (/boot) to /root/boot.bak.bz2

  DUMP: Date this dump completed:  Mon Aug  6 15:48:13 2018

  DUMP: Average transfer rate: 3853 kB/s

  DUMP: Wrote 25670kB uncompressed, 23123kB compressed, 1.111:1

  DUMP: DUMP IS DONE

3、查看备份时间文件

[root@localhost /]# cat /etc/dumpdates

/dev/sda1 0 Mon Aug  6 15:48:07 2018 +0800

4、找一个文件复制到boot分区以便测试增量备份

 [root@localhost ~]# ll  -h

总用量 23M

-rw-------. 1 root root 1.1K 7  13 22:28 anaconda-ks.cfg

-rw-r--r--. 1 root root  23M 8   6 15:48 boot.bak.bz2

-rw-r--r--. 1 root root 7.9K 7月  13 22:28 install.log

-rw-r--r--. 1 root root 3.4K 7  13 22:28 install.log.syslog

[root@localhost ~]# cp  install.log  /boot/

5、第二次等级1增量备份/boot分区并压缩

[root@localhost ~]# dump  -1uj  -f /root/boot.bak1.bz2  /boot/

  DUMP: Date of this level 1 dump: Mon Aug  6 15:51:49 2018

  DUMP: Date of last level 0 dump: Mon Aug  6 15:48:07 2018

  DUMP: Dumping /dev/sda1 (/boot) to /root/boot.bak1.bz2

  DUMP: Date this dump completed:  Mon Aug  6 15:51:49 2018

  DUMP: Average transfer rate: 0 kB/s

  DUMP: Wrote 40kB uncompressed, 13kB compressed, 3.077:1

  DUMP: DUMP IS DONE

6、发现第二次备份只有14k,说明只备份了差异部分

[root@localhost ~]# ll -h

总用量 23M

-rw-------. 1 root root 1.1K 7  13 22:28 anaconda-ks.cfg

-rw-r--r--. 1 root root  14K 8   6 15:51 boot.bak1.bz2

-rw-r--r--. 1 root root  23M 8   6 15:48 boot.bak.bz2

-rw-r--r--. 1 root root 7.9K 7  13 22:28 install.log

7、查询各发分区的备份时间与备份级别

 [root@localhost ~]# dump -W

Last dump(s) done (Dump '>' file systems):

> /dev/sda2  (     /) Last dump: never

  /dev/sda1  ( /boot) Last dump: Level 1, Date Mon Aug  6 15:51:49 2018

> /dev/sda3  ( /data) Last dump: never

> /dev/sda7  (  /usr) Last dump: never

> /dev/sda5  (  /var) Last dump: never

 

 

二、恢复

 

1、恢复命令

restore  [模式选项]   [选项]

模式选项:

-C 使用对比模式,将备份的文件与现行的文件相互对比。

-i 使用互动模式,在进行还原操作时,restore指令将依序询问用户。

-t 查看模式,用于查看备份文件中拥有哪些数据

-r 进行还原操作。

选项:

-f 指定备份文件的文件名

 

2、恢复实例

1、修改一个文件名测试对比模式

[root@localhost boot]# mv vmlinuz-2.6.32-642.el6.x86_64 vmlinuz-2.6.32-642.el6.x86_64.bak

[root@localhost boot]# restore -C -f /root/boot.bak.bz2

Dump tape is compressed.

Dump   date: Mon Aug  6 15:48:07 2018

Dumped from: the epoch

Level 0 dump of /boot on localhost.localdomain:/dev/sda1

Label: none

filesys = /boot

restore: unable to stat ./vmlinuz-2.6.32-642.el6.x86_64: No such file or directory

Some files were modified!  1 compare errors

2、查看模式

[root@localhost /]# restore -t -f /root/boot.bak.bz2

Dump tape is compressed.

Dump   date: Mon Aug  6 15:48:07 2018

Dumped from: the epoch

Level 0 dump of /boot on localhost.localdomain:/dev/sda1

Label: none

         2   .

        11   ./lost+found

        12   ./grub

        40   ./grub/grub.conf

        13   ./grub/splash.xpm.gz

        25   ./grub/menu.lst

        26   ./grub/device.map

        18   ./vmlinuz-2.6.32-642.el6.x86_64

        23   ./initramfs-2.6.32-642.el6.x86_64.img

3、建立新目录以便分级恢复模式

[root@localhost /]# mkdir /bootbak

[root@localhost /]# cd /bootbak/

[root@localhost bootbak]# restore -r -f /root/boot.bak.bz2

Dump tape is compressed.

[root@localhost bootbak]# ls

config-2.6.32-642.el6.x86_64  initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz

efi                           lost+found                           System.map-2.6.32-642.el6.x86_64

grub                          restoresymtable                      vmlinuz-2.6.32-642.el6.x86_64

[root@localhost bootbak]# restore -r -f /root/boot.bak1.bz2

Dump tape is compressed.

[root@localhost bootbak]# ls

config-2.6.32-642.el6.x86_64         install.log                       System.map-2.6.32-642.el6.x86_64

efi                                  lost+found                        vmlinuz-2.6.32-642.el6.x86_64

grub                                 restoresymtable

initramfs-2.6.32-642.el6.x86_64.img  symvers-2.6.32-642.el6.x86_64.gz

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

情绪零碎碎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值