Linux

How to Create Backups with Fsarchiver on Linux

How to Create Backups with Fsarchiver on Linux

Creating reliable backups is essential for protecting your data from unexpected failures, corruption, or accidental deletion. One powerful and flexible tool available on Linux for creating backups is Fsarchiver. It is a versatile utility that can back up filesystems while preserving their attributes, compressing the data, and allowing for selective restoration. In this guide, we’ll walk you through installing and using Fsarchiver to create and restore backups on Linux.

Why Use Fsarchiver?
Fsarchiver offers several benefits:

Filesystem-Aware: It backs up entire filesystems while preserving attributes, permissions, and symbolic links.
Compression: It reduces the size of backups by compressing the data.
Flexible Restores: You can restore individual files or entire filesystems.
Multi-Platform: It supports various filesystems, including ext4, NTFS, and more.
Error Handling: If errors occur during backup, Fsarchiver skips corrupt files without stopping the entire process.
Step 1: Install Fsarchiver
Fsarchiver is available in most Linux distribution repositories, making installation straightforward.

On Ubuntu/Debian
Update the Package List:

sudo apt update

Install Fsarchiver:

sudo apt install fsarchiver

On Fedora
Install Fsarchiver:

sudo dnf install fsarchiver

On Arch Linux
Install Fsarchiver:

 

sudo pacman -S fsarchiver

Once installed, you can confirm the installation by running:

fsarchiver –version

Step 2: Creating a Backup with Fsarchiver
Fsarchiver creates archives of your filesystem. The basic syntax for creating a backup is:

sudo fsarchiver savefs

: The name of the archive where the backup will be stored.
: The device or partition you want to back up.
Example: Backing Up an ext4 Filesystem
If you want to back up the /dev/sda1 partition to an archive file named backup.fsa, the command will look like this:

sudo fsarchiver savefs /backups/backup.fsa /dev/sda1

Adding Compression
To reduce the size of the backup, Fsarchiver offers different levels of compression (from 1 to 9, with 9 being the highest):

sudo fsarchiver savefs -z 5 /backups/backup.fsa /dev/sda1

In this example, -z 5 specifies a medium compression level.

Multi-Volume Backups
Fsarchiver can split large backups into smaller chunks. This is especially useful when backing up to media with limited storage (e.g., DVDs or USB drives):

sudo fsarchiver savefs -s 4000 /backups/backup.fsa /dev/sda1

This command creates an archive with 4GB chunks.

Step 3: Verifying the Backup
After creating a backup, it’s a good practice to verify the integrity of the archive. Fsarchiver allows you to check for errors without restoring the backup:

sudo fsarchiver archinfo /backups/backup.fsa

This command shows detailed information about the archive, including the filesystems and their UUIDs, as well as any potential errors.

Step 4: Restoring a Backup with Fsarchiver
Restoring a backup is just as easy as creating one. The basic syntax is:

sudo fsarchiver restfs id=

: The archive you want to restore.
id=: The ID of the filesystem in the archive (starting from 0).
: The target device where you want to restore the backup.
Example: Restoring to a Partition
If you have a backup archive called backup.fsa and want to restore it to /dev/sda1, use this command:

sudo fsarchiver restfs /backups/backup.fsa id=0 /dev/sda1

Fsarchiver will automatically detect the filesystem type in the archive and restore it accordingly.

Selective File Restoration
If you only need to restore specific files or directories from the backup, you can use the –extract option. For example, to extract a specific file:

sudo fsarchiver restfs /backups/backup.fsa –extract /path/to/file /dev/sda1

This option allows flexibility when you don’t need to restore the entire filesystem.

Step 5: Advanced Features of Fsarchiver
Encrypting Backups
To enhance the security of your backups, Fsarchiver allows you to encrypt archives. You can do this by specifying the -K option followed by the encryption key:

sudo fsarchiver savefs -K your_password /backups/backup.fsa /dev/sda1

This ensures that your backup is encrypted and can only be restored using the correct password.

Handling Multiple Filesystems
If you want to back up multiple partitions or filesystems in one archive, you can include additional devices in the same command:

sudo fsarchiver savefs /backups/backup.fsa /dev/sda1 /dev/sda2

Fsarchiver will save each filesystem in the archive with a unique ID, allowing you to restore them individually later.

Step 6: Scheduling Backups with Cron
To automate backups, you can set up a cron job. For example, to create a backup of /dev/sda1 every day at midnight:

Open the cron configuration:

sudo crontab -e

Add the following line to schedule the backup:

0 0 * * * sudo fsarchiver savefs /backups/backup-$(date +\%Y-\%m-\%d).fsa /dev/sda1

This command will create a backup every day, appending the current date to the filename.

Thank you for visiting our site, you can check out our other related articles from the links below 🙂

How to Use dd in Linux Without Destroying Your Disk

Install and Use Open Source Disk Partitioning Tool GParted in Linux

How to Install and Use rsync on Ubuntu

How to Install and Use Duplicity to Automate Backups on Linux

If you would like to improve yourself in server management, you can purchase a server from our site, experiment and improve yourself in an affordable and reliable environment. I wish you good luck.:)

Conclusion

Fsarchiver is a powerful and flexible tool for creating reliable backups on Linux. It allows you to back up entire filesystems while preserving file attributes, supports various compression levels, and provides flexible restore options. Whether you’re backing up critical data or entire systems, Fsarchiver can help ensure your data is protected and recoverable.

By following this guide, you now know how to install and use Fsarchiver to create and restore backups, keeping your Linux system safe from data loss.

For further details, check out the official Fsarchiver documentation.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button