fbpx

Consistent Backup Using XFS File System & EBS Snapshots

Consistent Backup Using XFS File System & EBS Snapshots
Learn how to automate your Amazon Web Services (AWS) backup process using simple scripts and XFS Freeze with N2WS Backup & Recovery.
Share This Post

Welcome to a world where data security meets efficiency! In the digital realm, where every piece of information is invaluable, the importance of consistent backups cannot be overstated. If you’re navigating the vast landscape of file systems and storage solutions, you’ve likely encountered the XFS file system and EBS snapshots. Today, we’ll delve into the realm of seamless data protection, exploring how the combination of XFS and EBS snapshots can revolutionize your backup strategy.

What is XFS?

XFS (eXtended File System) is a high-performance file system that comes with several benefits, making it a popular choice for various applications.

Here are some key advantages of XFS:

  1. Scalability: XFS is designed with scalability in mind, allowing it to handle large amounts of data and high-performance workloads. As your storage requirements grow, XFS remains efficient and effective.
  2. Support for Large File Systems: XFS supports extremely large file systems and files, making it well-suited for applications that involve handling massive datasets, such as scientific research, media production, and data analytics.
  3. Excellent Performance: XFS is optimized for high-performance I/O operations, making it ideal for scenarios where fast data access is crucial. This is particularly advantageous in situations requiring quick read and write operations, such as databases and content delivery systems.
  4. Journaling: XFS uses a journaling file system, which enhances its reliability by keeping track of changes before committing them to the main file system. This helps prevent data corruption in the event of unexpected system failures or crashes.
  5. Online Resizing: XFS supports online resizing, allowing you to expand or shrink the file system without unmounting it. This flexibility is valuable for dynamic storage environments where changes to storage capacity need to be made without disrupting services.
  6. Snapshot Capabilities: XFS supports the creation of snapshots, enabling you to capture the state of the file system at a specific point in time. This feature is especially useful for backup and recovery purposes, providing a consistent and point-in-time copy of your data.
  7. Efficient Storage Allocation: XFS uses a delayed allocation mechanism, optimizing how it allocates disk space. This helps reduce fragmentation and enhances overall storage efficiency.
  8. Checksumming: XFS includes built-in checksumming to detect and correct data corruption. This contributes to the file system’s reliability by ensuring the integrity of stored data.

Overall, XFS is a robust and versatile file system that excels in handling large-scale, performance-intensive workloads, making it a preferred choice for many enterprise-level applications and systems.

Using XFS Freeze and EBS Snapshots

The command “xfs_freeze” is used to suspend or resume access to an XFS File system thus maintaining consistency. When the filesystem is suspended, all data is flushed to disk and then no IO is allowed on it, which can cause applications using this filesystem to pause, hang, and eventually fail. When performing backup using EBS snapshots, you can freeze the filesystem right before the snapshot is taken, and then unfreeze it right after the snapshot starts.

Since EBS snapshots are consistent for their point-in-time, the fact that the IO on the file system continues while the EBS snapshot is still being created does not affect the content of the snapshot. The actual command to use to freeze the XFS file system is:

xfs_freeze

This command stops new access to the file system and creates a stable image on disk. 

xfs_freeze -f 

The -f flag is used to freeze a specified XFS file system, so that new modifications cannot be undertaken. When the freeze command is applied, all ongoing transactions in the file system are allowed to complete. New write system calls are stopped, and other calls which can modify the file system are stopped.

All data, metadata, and log information are written to disk.  Any process trying to write to the frozen file system waits till the file system is unfrozen. 

xfs_freeze -u 

The -u flag is used to unfreeze the file system and allow IO to resume. Any file system modifications that were blocked by the freeze are unblocked and allowed to complete.

Using xfs_freeze with N2WS Backup & Recovery

N2WS Backup & Recovery is an enterprise-class backup and recovery solution for the EC2 cloud. It performs backups using AWS EBS snapshots and supports backup scripts to perform quiescence of applications and file systems.

When you activate backup scripts for a backup policy, you provide 3 scripts:

  1. the “before” script that is invoked right before the snapshots are taken,
  2. the “after” script that is invoked right after the EBS snapshots start,
  3. and the “complete” script which is invoked after the snapshots are completed.

You can use all 3 scripts or some of them. If you do not need a script, you can provide an empty one that does nothing. Read more about using backup scripts with N2WS in our documentation.

In the case of XFS, we need to freeze the file system in the “before” script and unfreeze it in the “after” script. Since the script is invoked on the N2WS server and not on the backed-up instance, we use SSH to connect to the backed-up instance and perform the operation.

So, the “before” script looks like this: 

#!/bin/bashssh -i <path to the pem file of the relevant key-pair> <username>@<server address> “sudo xfs_freeze -f <path to the file system mount point>”if [ $? -gt 0 ]; then  echo “Failed freezing XFS filesystem” 1>&2  exit 1else  echo “xfs freeze succeeded” 1>&2fi 

The “after” script looks similar, except the unfreeze option: 

#!/bin/bashssh -i <path to the pem file of the relevant key-pair> <username>@<server address> “sudo xfs_freeze -u <path to the file system mount point>”if [ $? -gt 0 ]; then  echo “Failed unfreezing XFS filesystem” 1>&2  exit 1else  echo “xfs unfreeze succeeded” 1>&2fi 

We direct output to “stderr” since N2WS will collect the output and allow us to view it from the web console. Since the time span between invoking these two scripts is a few seconds at most, it should not interfere with any operations in the production environment.

Checking for File System Consistency

Finally, after backup you may want to make sure that the backup of the XFS file system is consistent. You can do that by recovering the volume or the entire instance and run the “xfs_check” command while the device is unmounted.

xfs_check

If the filesystem is on a disk partition, the xfs_check command is: 

xfs_check -d partition

You’ll replace partition with the device name for the partition. For example:

/usr/disk/dsk1 

If the filesystem is on an lv logical volume, the xfs_check command is: 

xfs_check -d lvvolume

You’ll replace lvvolume for the device file for the logical volume. For example:

/usr/disk/lv1 

The xfs_check command does not repair any reported filesystem consistency problems, it only reports them. You can automate the whole test process by using N2WS’ CLI (more details here) To see the different editions with pricing and details, refer to N2Ws’ pricing and purchases page on our website. 

Next step

The easier way to automate EBS snapshots

Allowed us to save over $1 million in the management of AWS EBS snapshots...

N2WS vs AWS Backup

Why chose N2WS over AWS Backup? Find out the critical differences here.

N2WS in comparison to AWS Backup, offers a single console to manage backups across accounts or clouds. Here is a stylized screenshot of the N2WS dashboard.

Try N2WS for Free