差异备份,在全备的基础上做备份。因为tar命令不能实现差异备份,所以本文讲解如何用dump和restore命令实现。当然dump和restore命令也可以实现全备和增量备份。
一 创建备份目录 分区 挂载
[root@serv01 data]# mkdir /backup
[root@serv01 data]# fdisk /dev/sdb
[root@serv01 data]# fdisk /dev/sdc
[root@serv01 data]# mkfs.ext4 /dev/sdb1
[root@serv01 data]# mkfs.ext4 /dev/sdc1
[root@serv01 data]# mount /dev/sdb1 /data
[root@serv01 data]# mount /dev/sdc1/backup/
二 拷贝文件、修改配置文件
#拷贝文件
[root@serv01 data]# rm -rf *
[root@serv01 data]# cp /boot/* .
cp: omitting directory `/boot/efi'
cp: omitting directory `/boot/grub'
cp: omitting directory `/boot/lost+found'
#向fstab文件追加内容
[root@serv01 data]# echo "/dev/sdb1/data ext4 defaults 1 2" >> /etc/fstab
[root@serv01 data]# echo "/dev/sdc1/backup ext4 defaults 1 2" >> /etc/fstab
三 dump和restore——实现全备
[root@serv01 data]# yum install dump -y
#dump:支持增量备份和差异备份,只能对单独的分区进行备份
#0:全备
#u:把/etc/dumpdates更新
#f:备份后的名字
[root@serv01 data]# cd /backup/
[root@serv01 backup]# ls
lost+found
[root@serv01 backup]# rm -rf lost+found/
#第一次查看,发现dumpdates没有任何内容
[root@serv01 backup]# ls /etc/dumpdates
/etc/dumpdates
#备份
[root@serv01 backup]# dump -0uf data01.dump/data/
DUMP: Date of this level 0 dump: Fri Aug 2 18:57:53 2013
DUMP: Dumping /dev/sdb1 (/data) to data01.dump
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 59 blocks.
DUMP: Volume 1 started with block 1 at: Fri Aug 2 18:57:53 2013
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing data01.dump
DUMP: Volume 1 completed at: Fri Aug 2 18:57:53 2013
DUMP: Volume 1 50 blocks (0.05MB)
DUMP: 50 blocks (0.05MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 0 dump: Fri Aug 2 18:57:53 2013
DUMP: Date this dump completed: Fri Aug 2 18:57:53 2013
DUMP: Average transfer rate: 0 kB/s
DUMP: DUMP IS DONE
[root@serv01 backup]# ll
total 52
-rw-r--r—. 1 root root 51200 Aug 2 18:57 data01.dump
#查看dumpdates文件,发现已经更新了
[root@serv01 backup]# cat /etc/dumpdates
/dev/sdb1 0 Fri Aug 2 18:57:53 2013 +0800
#还原,数据没有了,重新备份
[root@serv01 backup]# cd /data
[root@serv01 data]# ls
lost+found
[root@serv01 data]# rm -rf *
[root@serv01 data]# cp /boot/* ./
cp: omitting directory `/boot/efi'
cp: omitting directory `/boot/grub'
cp: omitting directory `/boot/lost+found'
[root@serv01 data]# cd /backup/
[root@serv01 backup]# ls
data01.dump
[root@serv01 backup]# rm -rf *
[root@serv01 backup]# ls
[root@serv01 backup]# > /etc/dumpdates
[root@serv01 backup]# dump -0uf dump01.dump/data/
DUMP: Date of this level 0 dump: Fri Aug 2 19:02:20 2013
DUMP: Dumping /dev/sdb1 (/data) to dump01.dump
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 18674 blocks.
DUMP: Volume 1 started with block 1 at: Fri Aug 2 19:02:20 2013
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing dump01.dump
DUMP: Volume 1 completed at: Fri Aug 2 19:02:20 2013
DUMP: Volume 1 18670 blocks (18.23MB)
DUMP: 18670 blocks (18.23MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 0 dump: Fri Aug 2 19:02:20 2013
DUMP: Date this dump completed: Fri Aug 2 19:02:20 2013
DUMP: Average transfer rate: 0 kB/s
DUMP: DUMP IS DONE
#进入data目录,发现有数据
[root@serv01 backup]# cd /data
[root@serv01 data]# ls
config-2.6.32-131.0.15.el6.x86_64 symvers-2.6.32-131.0.15.el6.x86_64.gz vmlinuz-2.6.32-131.0.15.el6.x86_64
initramfs-2.6.32-131.0.15.el6.x86_64.img System.map-2.6.32-131.0.15.el6.x86_64
#全部删除,模拟数据丢失
[root@serv01 data]# rm -rf *
[root@serv01 data]# ls
#恢复数据
[root@serv01 data]# restore -rf/backup/dump01.dump
#恢复成功
[root@serv01 data]# ls
config-2.6.32-131.0.15.el6.x86_64 restoresymtable System.map-2.6.32-131.0.15.el6.x86_64
initramfs-2.6.32-131.0.15.el6.x86_64.img symvers-2.6.32-131.0.15.el6.x86_64.gz vmlinuz-2.6.32-131.0.15.el6.x86_64
[root@serv01 data]# cp /etc/passwd ./
[root@serv01 data]# ls
config-2.6.32-131.0.15.el6.x86_64 passwd symvers-2.6.32-131.0.15.el6.x86_64.gz vmlinuz-2.6.32-131.0.15.el6.x86_64
initramfs-2.6.32-131.0.15.el6.x86_64.img restoresymtable System.map-2.6.32-131.0.15.el6.x86_64
[root@serv01 data]# cd /backup/