CentOS 系統(tǒng)備份與恢復

CentOS備份與恢復命令說明:
CentOS系統(tǒng)通常使用dump/xfsdump命令進行系統(tǒng)分區(qū)/目錄備份,備份可以使用全量備份和增量備份,CentOS 進行系統(tǒng)備份時針對不同的文件系統(tǒng)使用不同的命令進行備份與恢復,例如,文件系統(tǒng)使用ext2/ext3/etx4使用dump備份命令和restore恢復命令,文件系統(tǒng)使用xfs使用xfsdump備份命令和xfsrestore恢復命令。所以,在CentOS系統(tǒng)分區(qū)/目錄備份或恢復進,建議先查看文件系統(tǒng)類型再使用對應的命令進行備份與恢復。

dump備份命令:

標準用法    dump  -0uj  –f  /opt/boot.bz2  /boot/

-level:就是我們說的 0~9 共 10 個備份級別,0是全量備份(默認),其它是增量備份;
-f  指定備份文件名;
-u:備份成功之后,把備份時間記錄在 /etc/dumpdates 文件中;
-v:顯示備份過程中更多的輸出信息;
-j:調用 bzlib 庫壓縮備份文件,其實就是把備份文件壓縮為 .bz2 格式,默認壓縮等級是 2;
-W:顯示允許被 dump 的分區(qū)的備份等級及備份時間;

restore恢復命令:
注意:要切換到當前需要恢復的目錄進行恢復

標準用戶   restore  -r   -f   /opt/boot.bz2

-f  指定要恢復的備份文件;
-C:比較備份數(shù)據(jù)和實際數(shù)據(jù)的變化。
-i:進入交互模式,手工選擇需要恢復的文件;
-t:查看模式,用于查看備份文件中擁有哪些數(shù)據(jù);
-r:還原模式,用于數(shù)據(jù)還原;

xfsdump命令:

標準用法      xfsdump  –f  /opt/boot_backup  /boot  -L  backup_boot  -M  boot

-L  :xfsdump  紀錄每次備份的 session 標頭,這里可以填寫針對此文件系統(tǒng)的簡易說明
-M  :xfsdump 可以紀錄儲存媒體的標頭,這里可以填寫此媒體的簡易說明
-f  指定備份文件名;
-I:大寫的“i”,從/var/lib/xfsdump/inventory 列出目前備份的信息狀態(tài)。
-l:是L的小寫,就是指定等級,有0~9共10個等級,默認為0,即完整備份。

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

標準用法   xfsrestore  -f  /opt/boot_backup  /boot/

-f  指定要恢復的備份文件;

dumprestore備份與恢復(文件系統(tǒng)etx2/etx3/etx4)操作:

提示:以備份/boot目錄為演示,xfsdump與xfsrestore備份與恢復操作步驟一樣,只是命令不相同而已。

1、查看CentOS使用的文件系統(tǒng)類型

[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系統(tǒng)默認沒有安裝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、掛載系統(tǒng) / 根分區(qū)和 /boot分區(qū)

image.png
image.png

8、使用restore恢復命令進行boot目錄恢復


image.png

9、重啟進入系統(tǒng)測試


image.png
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容