XFS Dump
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7...
Backup of " / " {root} directory:
/boot - 1GB - xfs __standard_partition | |
My scenario | /home - 1GB - xfs ___lvm |
/ - 32GB - xfs ___lvm |
- mkdir /rescue_disk && mkdir /rescue_disk/backups && mkdir /rescue_disk/xfsdump
- chmod 700 /rescue_disk/backups && chmod 700 /rescue_disk/xfsdump
- cd /rescue_disk/backups
- df -hv
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos7-root 31G 4.1G 27G 13% /
devtmpfs 907M 0 907M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.7M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/mapper/centos7-home 953M 42M 912M 5% /home
/dev/vda1 950M 183M 768M 20% /boot
tmpfs 184M 0 184M 0% /run/user/0 - lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 953M 0 part /boot
└─vda2 252:2 0 47.1G 0 part
├─centos7-lv_cache_cdata 253:0 0 12.1G 0 lvm
│ └─centos7-root 253:3 0 31G 0 lvm /
├─centos7-lv_cache_cmeta 253:1 0 28M 0 lvm
│ └─centos7-root 253:3 0 31G 0 lvm /
├─centos7-root_corig 253:2 0 31G 0 lvm
│ └─centos7-root 253:3 0 31G 0 lvm /
├─centos7-swap 253:4 0 2.9G 0 lvm [SWAP]
└─centos7-home 253:5 0 956M 0 lvm /home - additional backup of boot-system:
tar czf boot.tar.gz /boot mysqldump -u root -p isp3_cpanel > isp3_cpanel.sql mysqldump -u root -p webmail > webmail.sql
- xfsdump -f /rescue_disk/xfsdump/root.xfsdump /
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> root_backup
session label entered: "root_backup"
--------------------------------- end dialog ---------------------------------
xfsdump: saving user quota information for: /
xfsdump: saving group quota information for: /
xfsdump: level 0 dump of website.development.hk:/
xfsdump: dump date: Mon Apr 1 22:44:45 2019
xfsdump: session id: 9200bb8a-cde1-4b41-b4d5-7a6818ae5423
xfsdump: session label: "root_backup"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 4370714176 bytes
xfsdump: /var/lib/xfsdump/inventory created
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> centos7
media label entered: "centos7"
--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 5604529112 bytes
xfsdump: dump size (non-dir files) : 5526097992 bytes
xfsdump: dump complete: 93 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /rescue_disk/xfsdump/root.xfsdump OK (success)
xfsdump: Dump Status: SUCCESS
--total_backup_takes_less_than_minute-- - xfsdump -l 0 -f /rescue_disk/xfsdump/home.xfsdump /home
xfsdump -l 0 -f /rescue_disk/xfsdump/boot.xfsdump /boot
RECOVERY- xfsrestore -f /rescue_disk/xfsdump/root.xfsdump /
additional tips: (database recovery)
systemctl stop mysql
mysql -u root -p database_name < database_name.sql
chown -R mysql:mysql /var/lib/mysql
systemctl restart mysql
Documentation
3.6. Suspending an XFS File System
xfs_freeze mount-point
Note
xfs_freeze -f /mount/point
xfs_freeze -u /mount/point
3.7. Backing Up and Restoring XFS File Systems
- xfsdump for creating the backup
- xfsrestore for restoring from backup
3.7.1. Features of XFS Backup and Restoration
Backup
- Perform backups to regular file images.Only one backup can be written to a regular file.
- Perform backups to tape drives.The xfsdump utility also allows you to write multiple backups to the same tape. A backup can span multiple tapes.To back up multiple file systems to a single tape device, simply write the backup to a tape that already contains an XFS backup. This appends the new backup to the previous one. By default, xfsdump never overwrites existing backups.
- Create incremental backups.The xfsdump utility uses dump levels to determine a base backup to which other backups are relative. Numbers from 0 to 9 refer to increasing dump levels. An incremental backup only backs up files that have changed since the last dump of a lower level:
- To perform a full backup, perform a level 0 dump on the file system.
- A level 1 dump is the first incremental backup after a full backup. The next incremental backup would be level 2, which only backs up files that have changed since the last level 1 dump; and so on, to a maximum of level 9.
- Exclude files from a backup using size, subtree, or inode flags to filter them.
Restoration
3.7.2. Backing Up an XFS File System
Procedure 3.1. Backing Up an XFS File System
- Use the following command to back up an XFS file system:
xfsdump -l level [-L label] -f backup-destination path-to-xfs-filesystem
- Replace level with the dump level of your backup. Use
0
to perform a full backup or1
to9
to perform consequent incremental backups. - Replace backup-destination with the path where you want to store your backup. The destination can be a regular file, a tape drive, or a remote tape device. For example,
/backup-files/Data.xfsdump
for a file or/dev/st0
for a tape drive. - Replace path-to-xfs-filesystem with the mount point of the XFS file system you want to back up. For example,
/mnt/data/
. The file system must be mounted. - When backing up multiple file systems and saving them on a single tape device, add a session label to each backup using the
-L label
option so that it is easier to identify them when restoring. Replace label with any name for your backup: for example,backup_data
.
Example 3.4. Backing up Multiple XFS File Systems
- To back up the content of XFS file systems mounted on the
/boot/
and/data/
directories and save them as files in the/backup-files/
directory:xfsdump -l 0 -f /backup-files/boot.xfsdump /boot
xfsdump -l 0 -f /backup-files/data.xfsdump /data
- To back up multiple file systems on a single tape device, add a session label to each backup using the
-L label
option:xfsdump -l 0 -L "backup_boot" -f /dev/st0 /boot
xfsdump -l 0 -L "backup_data" -f /dev/st0 /data
Additional Resources
- For more information about backing up XFS file systems, see the xfsdump(8) man page.
3.7.3. Restoring an XFS File System from Backup
Prerequisites
- You need a file or tape backup of XFS file systems, as described in Section 3.7.2, “Backing Up an XFS File System”.
Procedure 3.2. Restoring an XFS File System from Backup
- The command to restore the backup varies depending on whether you are restoring from a full backup or an incremental one, or are restoring multiple backups from a single tape device:
xfsrestore [-r] [-S session-id] [-L session-label] [-i]
-f backup-location
restoration-path
- Replace backup-location with the location of the backup. This can be a regular file, a tape drive, or a remote tape device. For example,
/backup-files/Data.xfsdump
for a file or/dev/st0
for a tape drive. - Replace restoration-path with the path to the directory where you want to restore the file system. For example,
/mnt/data/
. - To restore a file system from an incremental (level 1 to level 9) backup, add the
-r
option. - To restore a backup from a tape device that contains multiple backups, specify the backup using the
-S
or-L
options.The-S
lets you choose a backup by its session ID, while the-L
lets you choose by the session label. To obtain the session ID and session labels, use thexfsrestore -I
command.Replace session-id with the session ID of the backup. For example,b74a3586-e52e-4a4a-8775-c3334fa8ea2c
. Replace session-label with the session label of the backup. For example,my_backup_session_label
. - To use
xfsrestore
interactively, use the-i
option.The interactive dialog begins afterxfsrestore
finishes reading the specified device. Available commands in the interactivexfsrestore
shell includecd
,ls
,add
,delete
, andextract
; for a complete list of commands, use thehelp
command.
Example 3.5. Restoring Multiple XFS File Systems
/mnt/
:xfsrestore -f /backup-files/boot.xfsdump /mnt/boot/
xfsrestore -f /backup-files/data.xfsdump /mnt/data/
xfsrestore -f /dev/st0 -L "backup_boot" /mnt/boot/
xfsrestore -f /dev/st0 -S "45e9af35-efd2-4244-87bc-4762e476cbab" /mnt/data/
Informational Messages When Restoring a Backup from a Tape
xfsrestore
utility might issue messages. The messages inform you whether a match of the requested backup has been found when xfsrestore
examines each backup on the tape in sequential order. For example:xfsrestore: preparing drive xfsrestore: examining media file 0 xfsrestore: inventory session uuid (8590224e-3c93-469c-a311-fc8f23029b2a) does not match the media header's session uuid (7eda9f86-f1e9-4dfd-b1d4-c50467912408) xfsrestore: examining media file 1 xfsrestore: inventory session uuid (8590224e-3c93-469c-a311-fc8f23029b2a) does not match the media header's session uuid (7eda9f86-f1e9-4dfd-b1d4-c50467912408) [...]
Additional Resources
- For more information about restoring XFS file systems, see the xfsrestore(8) man page.
3.9. Other XFS File System Utilities
- xfs_fsr
- Used to defragment mounted XFS file systems. When invoked with no arguments,
xfs_fsr
defragments all regular files in all mounted XFS file systems. This utility also allows users to suspend a defragmentation at a specified time and resume from where it left off later.In addition,xfs_fsr
also allows the defragmentation of only one file, as inxfs_fsr /path/to/file
. Red Hat advises not to periodically defrag an entire file system because XFS avoids fragmentation by default. System wide defragmentation could cause the side effect of fragmentation in free space. - xfs_bmap
- Prints the map of disk blocks used by files in an XFS filesystem. This map lists each extent used by a specified file, as well as regions in the file with no corresponding blocks (that is, holes).
- xfs_info
- Prints XFS file system information.
- xfs_admin
- Changes the parameters of an XFS file system. The
xfs_admin
utility can only modify parameters of unmounted devices or file systems. - xfs_copy
- Copies the contents of an entire XFS file system to one or more targets in parallel.
- xfs_metadump
- Copies XFS file system metadata to a file. Red Hat only supports using the
xfs_metadump
utility to copy unmounted file systems or read-only mounted file systems; otherwise, generated dumps could be corrupted or inconsistent. - xfs_mdrestore
- Restores an XFS metadump image (generated using
xfs_metadump
) to a file system image. - xfs_db
- Debugs an XFS file system.
man
pages.Live experience
xfs_info /
meta-data=/dev/mapper/centos7-root isize=512 agcount=4, agsize=732416 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2929664, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
yum install xfsdump
xfs_freeze -f /
]# xfsdump -l 0 -f /storage_data/dump_area/root.xfsdump /
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.7 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> rootdump
session label entered: "rootdump"
--------------------------------- end dialog ---------------------------------
xfsdump: level 0 dump of 94-237-72-121.sg-sin1.upcloud.host:/
xfsdump: dump date: Sat Mar 30 17:28:47 2019
xfsdump: session id: d69f486f-d291-4785-bf5a-c5c5e4483d73
xfsdump: session label: "rootdump"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 1037686144 bytes
xfsdump: /var/lib/xfsdump/inventory created
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> mediarootdump
media label entered: "mediarootdump"
--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 1007555104 bytes
xfsdump: dump size (non-dir files) : 990488744 bytes
xfsdump: dump complete: 141 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /storage_data/dump_area/root.xfsdump OK (success)
xfsdump: Dump Status: SUCCESS
xfs_freeze -u /