xfsrestore-備份還原

5.打包與壓縮

本章同步視頻:https://edu.51cto.com/sd/e4874

5.3.3 XFS 文件系統還原xfsrestore

1.xfsrestore - XFS filesystem incremental restore utilitysession

[root@study ~]# xfsrestore -I                           dom

 <==用來察看備份文件資料ide

[root@study ~]# xfsrestore [-f 備份檔] [-L S_label] [-s] 待復原目錄工具

<==單一檔案全系統復原post

[root@study ~]# xfsrestore [-f 備份文件] -r 待復原目錄ui

<==透過累積備份文件來複原系統spa

[root@study ~]# xfsrestore [-f 備份文件] -i待復原目錄命令行

<==進入互動模式rest

選項與參數:orm

-I  :跟xfsdump相同的輸出!可查詢備份數據,包括 Label 名稱與備份時間等

-f  :後面接的就是備份檔!

-L  :就是 Session 的 Label name 喔!可用 -I 查詢到的數據,在這個選項後輸入!

-s  :須要接某特定目錄,亦即僅復原某一個檔案或目錄之意!

-r  :若是是用檔案來儲存備份數據,那這個就不須要使用。若是是一個磁帶內有多個檔案,須要這東西來達成累積復原

-i:進入互動模式,進階管理員使用的!通常咱們不太須要操做它!

2.查看備份信息

[root@localhost mnt]# xfsrestore -I

file system 0:

fs id:  f598c75c-bd26-4543-af2f-8192841c4c8b

session 0:

mount point: localhost.localdomain:/mnt/sda3

device:  localhost.localdomain:/dev/sda3

time:  Tue Mar 31 20:42:51 2020

session label: "dump_sda3_20200331"

session id: b2315293-f79f-43b2-9276-157268eea187

level:  0

resumed: NO

subtree: NO

streams: 1

stream 0:

pathname: /tmp/sda3

start:  ino 131 offset 0

end:  ino 132 offset 0

interrupted: NO

media files: 1

media file 0:

mfile index: 0

mfile type: data

mfile size: 21656

mfile start: ino 131 offset 0

mfile end: ino 132 offset 0

media label: "sda3"

media id: 23a27bd0-e47b-4bee-9005-d530e6303f63

session 1:

mount point: localhost.localdomain:/mnt/sda3

device:  localhost.localdomain:/dev/sda3

time:  Tue Mar 31 20:47:58 2020

session label: "dump_sda3_20200331-1"

session id: 989e4ade-b8c3-40be-9714-10c648f6b46c

level:  1

resumed: NO

subtree: NO

streams: 1

stream 0:

pathname: /tmp/sda3-1

start:  ino 132 offset 0

end:  ino 133 offset 0

interrupted: NO

media files: 1

media file 0:

mfile index: 0

mfile type: data

mfile size: 21680

mfile start: ino 132 offset 0

mfile end: ino 133 offset 0

media label: "sda3"

media id: 42121b62-abf0-4e26-98f1-48d50f01b633

session 2:

mount point: localhost.localdomain:/mnt/sda3

device:  localhost.localdomain:/dev/sda3

time:  Tue Mar 31 20:56:34 2020

session label: "dump_sda3_20200331-2"

session id: 1a6e946b-fd0e-4e70-bb00-b82c04291de7

level:  2

resumed: NO

subtree: NO

streams: 1

stream 0:

pathname: /tmp/sda3-2

start:  ino 133 offset 0

end:  ino 137 offset 0

interrupted: NO

media files: 1

media file 0:

mfile index: 0

mfile type: data

mfile size: 23624

mfile start: ino 133 offset 0

mfile end: ino 137 offset 0

media label: "sda3"

media id: f410ea13-eada-4566-87c8-844b1a939ce1

xfsdump: Dump Status: SUCCESS

3.還原level0

[root@localhost mnt]# rm -f sda3/*

[root@localhost mnt]# ls sda3/

 

[root@localhost mnt]# xfsrestore -f /tmp/sda3 /mnt/sda3/

xfsrestore: using file dump (drive_simple) strategy

xfsrestore: version 3.1.3 (dump format 3.0) - type ^C for status and control

xfsrestore: searching media for dump

xfsrestore: examining media file 0

xfsrestore: dump description:

xfsrestore: hostname: localhost.localdomain

xfsrestore: mount point: /mnt/sda3

xfsrestore: volume: /dev/sda3

xfsrestore: session time: Tue Mar 31 20:42:51 2020

xfsrestore: level: 0

xfsrestore: session label: "dump_sda3_20200331"

xfsrestore: media label: "sda3"

xfsrestore: file system id: f598c75c-bd26-4543-af2f-8192841c4c8b

xfsrestore: session id: b2315293-f79f-43b2-9276-157268eea187

xfsrestore: media id: 23a27bd0-e47b-4bee-9005-d530e6303f63

xfsrestore: using online session inventory

xfsrestore: searching media for directory dump

xfsrestore: reading directories

xfsrestore: 1 directories and 1 entries processed

xfsrestore: directory post-processing

xfsrestore: restoring non-directory files

xfsrestore: restore complete: 0 seconds elapsed

xfsrestore: Restore Summary:

xfsrestore:   stream 0 /tmp/sda3 OK (success)

xfsrestore: Restore Status: SUCCESS

[root@localhost mnt]# ls sda3/

1.txt

4.還原level 1

[root@localhost mnt]# xfsrestore -f /tmp/sda3-1 /mnt/sda3/

[root@localhost mnt]# ls sda3/

1.txt  2.txt

5.還原level 2

[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 /mnt/sda3/

[root@localhost mnt]# ls sda3/

1.txt  2.txt  3.txt  4.txt  5.txt  6.txt

6.交互式部分還原

[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 -i /mnt/sda3/

xfsrestore: using file dump (drive_simple) strategy

xfsrestore: version 3.1.3 (dump format 3.0) - type ^C for status and control

xfsrestore: searching media for dump

xfsrestore: examining media file 0

xfsrestore: dump description:

xfsrestore: hostname: localhost.localdomain

xfsrestore: mount point: /mnt/sda3

xfsrestore: volume: /dev/sda3

xfsrestore: session time: Tue Mar 31 20:56:34 2020

xfsrestore: level: 2

xfsrestore: session label: "dump_sda3_20200331-2"

xfsrestore: media label: "sda3"

xfsrestore: file system id: f598c75c-bd26-4543-af2f-8192841c4c8b

xfsrestore: session id: 1a6e946b-fd0e-4e70-bb00-b82c04291de7

xfsrestore: media id: f410ea13-eada-4566-87c8-844b1a939ce1

xfsrestore: using online session inventory

xfsrestore: searching media for directory dump

xfsrestore: reading directories

xfsrestore: 1 directories and 6 entries processed

xfsrestore: directory post-processing

 ================= subtree selection dialog ==================

the following commands are available:

       pwd

ls [ <path> ]

cd [ <path> ]

add [ <path> ]

delete [ <path> ]

       extract

       quit

       help

 -> ls

             136 6.txt

             135 5.txt

             134 4.txt

             133 3.txt

             132 2.txt

             131 1.txt

 -> add 2.txt     #本條無效,由於2.txt不在本次備份文件中

 -> add 4.txt

 -> add 6.txt

 -> extract

 --------------------------------- end dialog ---------------------------------

xfsrestore: restoring non-directory files

xfsrestore: restore complete: 97 seconds elapsed

xfsrestore: Restore Summary:

xfsrestore:   stream 0 /tmp/sda3-2 OK (success)

xfsrestore: Restore Status: SUCCESS

[root@localhost mnt]# ls sda3/

4.txt  6.txt

7.非交互式部分還原

若是隻想要復原某一個目錄或檔案的話,直接加上『 -s 目錄』這個選項與參數便可!前提是你要知道被還原的文檔名。

[root@localhost mnt]# xfsrestore -f /tmp/sda3-2 -s 6.txt /mnt/sda3

[root@localhost mnt]# ls sda3/

6.txt

5.4 其餘備份工具

5.4.1 dd - convert and copy a file

1.語法

[root@study ~]# dd if="input_file" of="output_file" bs="block_size" count="number"

選項與參數:

if   :就是 input file ~也能夠是裝置!

of   :就是 output file~也能夠是裝置;

bs   :規劃的一個 block 的大小,若未指定則預設是 512 bytes(一個 sector 的大小)

count:多少個 bs 的意思。

2.用法

(1)將本地的/dev/hdb整盤備份到/dev/hdd

[root@localhost ~]# dd if=/dev/hdb of=/dev/hdd

(2)將/dev/hdb全盤數據備份到指定路徑的image文件

[root@localhost ~]# dd if=/dev/hdb of=/root/image

(3)將備份文件恢復到指定盤

[root@localhost ~]# dd if=/root/image of=/dev/hdb

(4)備份與恢復MBR

[root@localhost ~]# dd if=/dev/hda of=/root/image count=1 bs=512

[root@localhost ~]# dd if=/root/image of=/dev/had

3./dev/null

        把/dev/null看做"黑洞", 它等價於一個只寫文件,全部寫入它的內容都會永遠丟失.,而嘗試從它那兒讀取內容則什麼也讀不到。然而, /dev/null對命令行和腳本都很是的有用。

(1)禁止標準輸出

[root@localhost ~]# echo "aaaa"

aaaa

[root@localhost ~]# echo "aaaa" >/dev/null

(2)禁止標準錯誤輸出

[root@localhost ~]# cat aaaaa

cat: aaaaa: No such file or directory

[root@localhost ~]# cat aaaaa 2>/dev/null

(3)禁止標準輸出和標準錯誤輸出

[root@localhost tmp]# ls

root  test

[root@localhost tmp]# cat root

aaaaa

[root@localhost tmp]# cat calf

cat: calf: No such file or directory

[root@localhost tmp]# cat root calf >/dev/null 2>/dev/null

(4)清空文件內容

[root@localhost tmp]# cat /dev/null >root

[root@localhost tmp]# cat root

4./dev/zero

        /dev/zero也是一個僞文件, 但它實際上產生接二連三的null的流(二進制的零流,而不是ASCII型的)。  /dev/zero主要的用處是用來建立一個指定長度用於初始化的空文件,就像臨時交換文件。

(1)建立一個10M大小的臨時文件test

[root@localhost tmp]# dd if=/dev/zero of=test bs=1M count=10

10+0 records in

10+0 records out

10485760 bytes (10 MB) copied, 0.021191 s, 495 MB/s

5.5 總結

l  壓縮指令爲透過一些運算方法去將本來的檔案進行壓縮,以減小檔案所佔用的磁盤容量。

l  壓縮文件案的擴展名大可能是:『*.gz, *.bz2, *.xz, *.tar, *.tar.gz, *.tar.bz2, *.tar.xz』

l  常見的壓縮指令有 gzip, bzip2, xz。壓縮率最佳的是 xz。

l  tar 能夠用來進行檔案打包,並可支持 gzip, bzip2, xz 的壓縮。

lxfsdump 指令可備份文件系統或單一目錄,xfsrestore 指令可還原被 xfsdump 建置的備份檔;