美文网首页
CentOS 系统备份与恢复

CentOS 系统备份与恢复

作者: DB哥 | 来源:发表于2020-04-18 18:25 被阅读0次

CentOS备份与恢复命令说明:
CentOS系统通常使用dump/xfsdump命令进行系统分区/目录备份,备份可以使用全量备份和增量备份,CentOS 进行系统备份时针对不同的文件系统使用不同的命令进行备份与恢复,例如,文件系统使用ext2/ext3/etx4使用dump备份命令和restore恢复命令,文件系统使用xfs使用xfsdump备份命令和xfsrestore恢复命令。所以,在CentOS系统分区/目录备份或恢复进,建议先查看文件系统类型再使用对应的命令进行备份与恢复。

dump备份命令:

标准用法    dump  -0uj  –f  /opt/boot.bz2  /boot/

-level:就是我们说的 0~9 共 10 个备份级别,0是全量备份(默认),其它是增量备份;
-f  指定备份文件名;
-u:备份成功之后,把备份时间记录在 /etc/dumpdates 文件中;
-v:显示备份过程中更多的输出信息;
-j:调用 bzlib 库压缩备份文件,其实就是把备份文件压缩为 .bz2 格式,默认压缩等级是 2;
-W:显示允许被 dump 的分区的备份等级及备份时间;

restore恢复命令:
注意:要切换到当前需要恢复的目录进行恢复

标准用户   restore  -r   -f   /opt/boot.bz2

-f  指定要恢复的备份文件;
-C:比较备份数据和实际数据的变化。
-i:进入交互模式,手工选择需要恢复的文件;
-t:查看模式,用于查看备份文件中拥有哪些数据;
-r:还原模式,用于数据还原;

xfsdump命令:

标准用法      xfsdump  –f  /opt/boot_backup  /boot  -L  backup_boot  -M  boot

-L  :xfsdump  纪录每次备份的 session 标头,这里可以填写针对此文件系统的简易说明
-M  :xfsdump 可以纪录储存媒体的标头,这里可以填写此媒体的简易说明
-f  指定备份文件名;
-I:大写的“i”,从/var/lib/xfsdump/inventory 列出目前备份的信息状态。
-l:是L的小写,就是指定等级,有0~9共10个等级,默认为0,即完整备份。

xfsrestore 恢复命令:
注意: /boot/是你要恢复的目录或文件

标准用法   xfsrestore  -f  /opt/boot_backup  /boot/

-f  指定要恢复的备份文件;

dumprestore备份与恢复(文件系统etx2/etx3/etx4)操作:

提示:以备份/boot目录为演示,xfsdump与xfsrestore备份与恢复操作步骤一样,只是命令不相同而已。

1、查看CentOS使用的文件系统类型

[root@disk01 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 189G 1.7G 178G 1% /
devtmpfs devtmpfs 981M 0 981M 0% /dev
tmpfs tmpfs 992M 0 992M 0% /dev/shm
tmpfs tmpfs 992M 9.6M 982M 1% /run
tmpfs tmpfs  992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 ext4 477M 94M 354M 21% /boot
tmpfs tmpfs 199M 0 199M 0% /run/user/0

2、配置阿里yum源和epel源

curl -o /etc/yum.repos.d/CentOS-Base.repo [http://mirrors.aliyun.com/repo/Centos-7.repo](http://mirrors.aliyun.com/repo/Centos-7.repo)
curl -o /etc/yum.repos.d/epel.repo [http://mirrors.aliyun.com/repo/epel-7.repo](http://mirrors.aliyun.com/repo/epel-7.repo)
yum makecache

3、安装dump工具
提示:CentOS系统默认没有安装dump工具

yum install -y dump

4、使用dump命令备份/boot/目录

[root@disk01 ~]# mkdir /test
[root@disk01 ~]# dump -0uj -f /test/boot.bz2 /boot/
 DUMP: Date of this level 0 dump: Sat Apr 18 11:59:09 2020
 DUMP: Dumping /dev/sda1 (/boot) to /test/boot.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 93888 blocks.
 DUMP: Volume 1 started with block 1 at: Sat Apr 18 11:59:09 2020
 DUMP: dumping (Pass III) [directories]
 DUMP: dumping (Pass IV) [regular files]
 DUMP: Closing /test/boot.bz2
 DUMP: Volume 1 completed at: Sat Apr 18 11:59:17 2020
 DUMP: Volume 1 took 0:00:08
 DUMP: Volume 1 transfer rate: 10709 kB/s
 DUMP: Volume 1 94650kB uncompressed, 85674kB compressed, 1.105:1
 DUMP: 94650 blocks (92.43MB) on 1 volume(s)
 DUMP: finished in 8 seconds, throughput 11831 kBytes/sec
 DUMP: Date of this level 0 dump: Sat Apr 18 11:59:09 2020
 DUMP: Date this dump completed: Sat Apr 18 11:59:17 2020
 DUMP: Average transfer rate: 10709 kB/s
 DUMP: Wrote 94650kB uncompressed, 85674kB compressed, 1.105:1
 DUMP: DUMP IS DONE
[root@disk01 ~]# ls -lrth /test/
total 84M
-rw-r--r--. 1 root root 84M Apr 18 11:59 boot.bz2

5、删除/boot/目录所有文件仅保存一个文件存在以便作对比,致使CentOS无法进入GRUB菜单

[root@disk01 ~]# rm -rf /boot/*
[root@disk01 ~]# echo "test" > /boot/test.txt
[root@disk01 ~]# ls -l /boot/
total 2
-rw-r--r--. 1 root root 5 Apr 18 17:49 test.txt
image.png

6、启动CentOS安装光盘(U盘制作CentOS安装光盘也可以)进入Troubleshooting

image.png image.png image.png

7、挂载系统 / 根分区和 /boot分区

image.png image.png

8、使用restore恢复命令进行boot目录恢复


image.png

9、重启进入系统测试


image.png

相关文章

  • CentOS 系统备份与恢复

    CentOS备份与恢复命令说明:CentOS系统通常使用dump/xfsdump命令进行系统分区/目录备份,备份可...

  • GHOST备份与还原系统(图文)

    GHOST手动备份与还原系统 GHOST恢复: (恢复完毕) GHOST备份:

  • CentOS 7 系统备份与恢复

    一、备份 1. 使用tar命令备份 tar打包命令的特点: 保留权限 适合备份整个目录 可以选择不同的压缩方式 如...

  • Ubuntu 备份新方法

    ubuntu系统备份与恢复(也适用于其他linux系统) Acronis 是全球最佳备份和恢复软件 ATI 201...

  • 备份与恢复

    备份与恢复 备份概述 1、Linux系统需要备份的数据 /root/目录: /home/目录: /var/spoo...

  • 数据备份与恢复产品技术介绍

    数据备份与恢复产品是指实现和管理信息系统数据备份和恢复过程的产品。 按照备份数据量,可以分为:完全备份、差异备份和...

  • CentOS更改yum源与更新系统

    CentOS更改yum源与更新系统 首先备份/etc/yum.repos.d/CentOS-Base.repo m...

  • 基础环境搭建

    Centos7下环境搭建 CentOS更改yum源与更新系统 [1]首先备份/etc/yum.repos.d/Ce...

  • 将Centos的yum源更换为国内的阿里云源

    CentOS系统更换软件安装源 第一步:备份你的原镜像文件,以免出错后可以恢复。 mv /etc/yum.repo...

  • MySQL备份和恢复

    1、什么是备份和恢复? 备份:存储的数据副本;原始数据:持续改变;恢复:把副本应用到线上系统;仅能恢复至备份操作时...

网友评论

      本文标题:CentOS 系统备份与恢复

      本文链接:https://www.haomeiwen.com/subject/eanwvhtx.html