1. 程式人生 > >實戰:xfs檔案系統的備份和恢復

實戰:xfs檔案系統的備份和恢復

# 概述 XFS提供了 xfsdump 和 xfsrestore 工具協助備份XFS檔案系統中的資料。xfsdump 按inode順序備份一個XFS檔案系統。 centos7選擇xfs格式作為預設檔案系統,而且不再使用以前的ext,仍然支援ext4,xfs專為大資料產生,每個單個檔案系統最大可以支援8eb,單個檔案可以支援16tb,不僅資料量大,而且擴充套件性高。還可以通過xfsdump,xfsrestore來備份和恢復。 與傳統的UNIX檔案系統不同,XFS不需要在備份前被解除安裝;對使用中的XFS檔案系統做備份就可以保證映象的一致性。XFS的備份和恢復的過程是可以被中斷然後繼續的,無須凍結檔案系統。xfsdump 甚至提供了高效能的多執行緒備份操作——它把一次dump拆分成多個數據流,每個資料流可以被髮往不同的目的地 首先了解一下xfsdump的備份級別有以下兩種,預設為0(即完全備份) * 0 級別代表: 完全備份 * 1 到9級別代表: 增量備份 擴充套件: * 完全備份:每次都把指定的備份目錄完整的複製一遍,不管目錄下的檔案有沒有變化; * 增量備份:每次將之前(第一次、第二次、直到前一次)做過備份之後有變化的檔案進行備份; * 差異備份:每次都將第一次完整備份以來有變化的檔案進行備份。 ## 環境準備 ### 實驗環境 系統CENTOS8 新增一塊虛擬硬碟(準備一個測試分割槽) 正常使用一塊磁碟過程如下: 新增磁碟大小:2G ->分割槽->格式化->掛載 1. 虛擬機器新增2G硬碟 2. 開機後檢視裝置 使用fdisk -l檢視新增硬碟 ``` Last login: Tue Oct 20 04:13:20 2020 from 10.0.0.1 [root@C8-3 ~]# fdisk -l Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xbfcdb101 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 41943039 39843840 19G 8e Linux LVM Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes ``` 3. 給新增硬碟分割槽 ``` [root@C8-3 ~]# fdisk /dev/sdb #使用fdisk命令分割槽 Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x467c42d4. Command (m for help): m #檢視有哪些命令可以用 Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition F list free unpartitioned space l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition Misc m print this menu u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table Command (m for help): n #選擇新建一個分割槽 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p #建立主分割槽 Partition number (1-4, default 1): #直接回車預設值 First sector (2048-4194303, default 2048): #起始扇區,回車預設 Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): #結束扇區,回車預設分配全部空間 Created a new partition 1 of type 'Linux' and of size 2 GiB. Command (m for help): w #將以上操作寫入硬碟分割槽表,結束分割槽 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@C8-3 ~]# lsblk #檢視分割槽是否成功 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─cl-root 253:0 0 17G 0 lvm / └─cl-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 2G 0 disk └─sdb1 8:17 0 2G 0 part #分割槽成功但未掛載 ``` 4. 將新建分割槽格式化為xfs格式 使用mkfs.xfs格式化新分割槽 ``` [root@C8-3 ~]# type mkfs.xfs #檢視是否有此工具 mkfs.xfs is /usr/sbin/mkfs.xfs [root@C8-3 ~]# mkfs.xfs --help #檢視命令的幫助 mkfs.xfs: invalid option -- '-' unknown option -- Usage: mkfs.xfs /* blocksize */ [-b size=num] /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1] /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num, (sunit=value,swidth=value|su=num,sw=num|noalign), sectsize=num /* force overwrite */ [-f] /* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2, projid32bit=0|1,sparse=0|1] /* no discard */ [-K] /* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n sunit=value|su=num,sectsize=num,lazy-count=0|1] /* label */ [-L label (maximum 12 characters)] /* naming */ [-n size=num,version=2|ci,ftype=0|1] /* no-op info only */ [-N] /* prototype file */ [-p fname] /* quiet */ [-q] /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx] /* sectorsize */ [-s size=num] /* version */ [-V] dev