数据备份与数据恢复
数据备份dump
常用参数
参数 |
说明 |
-[0-9] |
备份层级 |
-f |
指定备份后的文件名 |
-j |
调用bzlib库压缩备份文件,后缀为bz2格式 |
-T |
指定开始备份的日期与时间 |
-u |
备份完毕后,在/etc/dumpdates中记录备份的文件系统、日期与时间 |
-t |
指定文件名 |
-W |
显示需要备份的文件及其最后一次备份的层级、时间、日期 |
-w |
与-W类似,但仅显示需要备份的文件 |
常用案例
- 备份分区支持增量备份
- 备份目录或文件不支持增量备份只能使用0级别备份
[root@localhost ~]# yum install dump
[root@localhost ~]# dump -0uj -f /opt/disk.bak0.bz2 /mnt/disk1/
DUMP: Date of this level 0 dump: Sun May 2 18:58:47 2021
DUMP: Dumping /dev/sdb1 (/mnt/disk1) to /opt/disk.bak0.bz2
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: Compressing output at compression level 2 (bzlib)
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 347 blocks.
DUMP: Volume 1 started with block 1 at: Sun May 2 18:58:47 2021
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /opt/disk.bak0.bz2
DUMP: Volume 1 completed at: Sun May 2 18:58:47 2021
DUMP: 330 blocks (0.32MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 0 dump: Sun May 2 18:58:47 2021
DUMP: Date this dump completed: Sun May 2 18:58:47 2021
DUMP: Average transfer rate: 0 kB/s
DUMP: Wrote 330kB uncompressed, 11kB compressed, 30.000:1
DUMP: DUMP IS DONE
[root@localhost ~]# echo "hello world" > /mnt/disk1/hello.txt
[root@localhost ~]# dump -1uj -f /opt/disk.bak1.bz2 /mnt/disk1/
DUMP: DUMP IS DONE
[root@localhost ~]# ll /opt/
total 28
-rw-r--r--. 1 root root 12226 May 2 18:58 disk.bak0.bz2
-rw-r--r--. 1 root root 12820 May 2 18:59 disk.bak1.bz2
[root@localhost ~]# cat /etc/dumpdates
/dev/sdb1 0 Sun May 2 18:58:47 2021 +0800
/dev/sdb1 1 Sun May 2 18:59:47 2021 +0800
[root@localhost ~]# dump -W
Last dump(s) done (Dump '>' file systems):
/dev/sdb1 (/mnt/disk1) Last dump: Level 1, Date Sun May 2 18:59:47 2021
数据恢复restore
常用参数
参数 |
说明 |
-C |
使用对比模式,将备份的文件与已存在的文件相互对比 |
-i |
使用交互模式,在进行还原操作时,restore指令将依次询问用户 |
-r |
进行还原模式 |
-t |
查看模式,看备份文件有哪些文件 |
-f |
从指定的文件中读取备份数据,进行还原操作 |
常用案例
#对比备份文件与现有文件的异同
[root@localhost opt]# mv /mnt/disk1/hello.txt /mnt/disk1/hello.md
[root@localhost opt]# restore -C -f disk.bak1.bz2
Dump tape is compressed.
Dump date: Sun May 2 18:59:47 2021
Dumped from: Sun May 2 18:58:47 2021
Level 1 dump of /mnt/disk1 on localhost.localdomain:/dev/sdb1
Label: none
filesys = /mnt/disk1
restore: unable to stat ./hello.txt: No such file or directory
Some files were modified! 1 compare errors
[root@localhost opt]# mv /mnt/disk1/hello.md /mnt/disk1/hello.txt
[root@localhost opt]# restore -C -f disk.bak1.bz2
Dump tape is compressed.
Dump date: Sun May 2 18:59:47 2021
Dumped from: Sun May 2 18:58:47 2021
Level 1 dump of /mnt/disk1 on localhost.localdomain:/dev/sdb1
Label: none
filesys = /mnt/disk1
#查看备份文件的内容有哪些
[root@localhost opt]# restore -t -f disk.bak0.bz2
Dump tape is compressed.
Dump date: Sun May 2 18:58:47 2021
Dumped from: the epoch
Level 0 dump of /mnt/disk1 on localhost.localdomain:/dev/sdb1
Label: none
2 .
11 ./lost+found
[root@localhost opt]# restore -t -f disk.bak1.bz2
Dump tape is compressed.
Dump date: Sun May 2 18:59:47 2021
Dumped from: Sun May 2 18:58:47 2021
Level 1 dump of /mnt/disk1 on localhost.localdomain:/dev/sdb1
Label: none
2 .
12 ./hello.txt
#恢复备份的文件,注意如果有增量备份需按照顺序进行恢复<时间从早到晚>
[root@localhost ~]# mkdir /opt/restore
[root@localhost ~]# cd /opt/restore/
[root@localhost restore]# restore -r -f /opt/disk.bak0.bz2
Dump tape is compressed.
[root@localhost restore]# ll
total 2064
drwx------. 2 root root 6 Mar 21 21:20 lost+found
-rw-------. 1 root root 2110472 May 2 21:35 restoresymtable
[root@localhost restore]# restore -r -f /opt/disk.bak1.bz2
Dump tape is compressed.
[root@localhost restore]# ll
total 2068
-rw-r--r--. 1 root root 12 May 2 18:59 hello.txt
drwx------. 2 root root 6 Mar 21 21:20 lost+found
-rw-------. 1 root root 2110552 May 2 21:35 restoresymtable