Have you ever lost a significant amount of work due to an unprecedented hard-drive malfunction? Anyone who lives a digital life has experienced this at least once. In this article, we will discuss how to backup an Arch Linux system.
Overview
One of the most crucial things to do in your digital life is backup. For people who work with sensitive data and crucial files, where data corruption might result in a big catastrophe, this is extremely important. For instance, your computer’s HDD, which is five years old, already contains your office document. Now that you have a backup of your vital files somewhere else, the HDD can finally rest in peace, regardless of when its end comes.
Several backup options for Linux systems provide professional-level performance and support.
These solutions are essentially pieces of software that create backup copies of crucial files in a secure location. Such a tool could come in handy in a lot of situations. For instance, things can go wrong too easily when you upgrade your system or install a significant component. A system backup would protect you in that situation from any issues.
You’ll learn how to use rsync to backup your ArchLinux system in this article. For those who don’t know, rsync is a Linux application that synchronizes data on a remote computer with an external HDD. It is free and open-source. Because of this, it acts as a way to secure your files by moving them to a backup server.
How to Backup an Arch Linux System
Rsync for Backup on Arch Linux System
This is a Linux system command-line tool. There is also a graphical user interface version called grsync. Professional administrators may make the most of it. It is preferable to utilize the graphical interface version for most users. In addition to grsync, luckbackup is another front-end utility that can also have rsync work.
The command line version is more practical for advanced users because it offers more flexibility for automation and scripting.
Use the command below to install rsync.
Syntax:
$ sudo pacman -S rsync
Here you can see that rsync has been installed successfully. To install rsync you will need root access or a sudo privileged user account.
Sample Arch Linux System Setup
For our example, we will work in a VMware-generated VM with ArchLinux. This will serve as our source, and a USB drive will serve as the location for our backup copy. In this article, we will be using the Command Line Interface. Do not be intimidated if you have no prior CLI experience. You’ll get used to it eventually.
Additionally, as a precaution, we advise encrypting the USB device to provide the files with an additional layer of security. Additionally, it would be ideal if the final location had a file system that is Linux-compatible.
Before attempting to create a backup for your system, we advise that you complete this guide to the conclusion and practice on a setup that is similar to the one you intend to use it on.
The approach:
Enter the following command to start the backup in the simulated environment:
Syntax:
$ sudo rsync -aAXv --delete --dry-run --exclude=/dev/* --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* --exclude=/run/* --exclude=/mnt/* --exclude=/media/* --exclude="swapfile" --exclude="lost+found" --exclude=".cache" --exclude="Downloads" --exclude=".VirtualBoxVMs" --exclude=".ecryptfs" / /run/media/dregs/ArchBackup/
In this screenshot, you can see that everything on the /etc/
directory will be backed up.
Here you can see that everything in the /usr/
directory is also going to be backed up.
Let’s look at each component in this command to understand what it accomplishes specifically:
Sudo and rsync are the first two components. Naturally, rsync is the application used here to create the backup, whereas sudo is for running any command that needs root privileges.
The next element is actually a combination of four flags, “-aAXv,” rather than a single element.
-a
, --archive
: The archive mode is activated by this option.
-A
, --acls
: You can tell the OS to keep the access control list by selecting this option.
-X
, --xattrs
: The security, system, trusted, and user attributes are maintained via this flag.
-v
, --verbose
: This flag is used to view the backup progress.
The -A
, -a
, and -X
flags act in tandem to protect the files’ integrity by preserving their attributes.
Then there is the -delete option, which directs to only backup those files not already present in the destination (in our example, USB). -delete should be used with great caution, as the updated versions of the files in the source replace or overwrite the older versions in the destination.
--dry-run
, -n
: This option is what keeps everything in a simulation, or shall we say, a trial run. With this option, the command doesn’t make any changes.
--exclude=PATTERN
: Some folders that should not be backed up are excluded using this parameter. We have skipped the /dev/, /proc/, /proc/ /sys/, /tmp/, /run/, /mnt/, and /media directories with the aforementioned command. This was just done to show that their exclusion (aside from /mnt/) isn’t required, as rsync doesn’t back up their contents automatically.
/-
: The contents we wish to back up are specified by this option.
/run/media/dregs/ArchBackup
: You are backing up to this directory.
After running the program in simulation mode, you can remove the “-dry-run
” option and run it once more to perform the actual backup.
Auto Backups using rsync on Arch Linux System
“rsync
” is a powerful program. What you can do with this flexible utility may fill an entire book. It is merely a file-copying utility in terms of technology; it is essentially a cp command with extra features like secure transfer files. This script uses rsync in a more understated but no less elegant way.
The basic aim is to discover a method to:
- Into directories recursively.
- Copy symbolic connections and preserve them as such.
- Maintain group memberships, devices, modification times, and special files’ permissions.
- Give more information and output in a verbose manner so that a log file may be created if necessary.
- File compression during transport can improve efficiency.
The rsync documentation is clearly written; after reading the summary of the possible choices, you may choose the -avz
flags as the preferable option with ease. An easy example is as follows:
Syntax:
$ rsync -avz <from folder>/ <destination folder>
The origin folder must be followed by a slash. “rsync
”, on the other hand, replicates the entire source folder, including it, to the final destination.
Use the following command to have rsync transport every change made to the second folder, destinationFolder, if you created two directories, one named FromFolder and the other DestinationFolder:
Example:
$ rsync -avz FromFolder/ DestinationFolder
“rsync
” prints something similar to this after you create a new file named New_File:
Sample Output:
Sending incremental file list
./
New_File
Sent 101 bytes received 32 bytes 265 bytes/sec
Total size is 0 speedup is 0.00
Incremental Copy
The incremental copy process type is indicated in the first line of the directive, which indicates that rsync only changes the file and not the entire archive when using its compression capabilities. When a command is run for the first time, the application copies the entire file; after fresh changes are made, only increments are made. The location, the file name, and performance information are the next outputs. When you check the rsync command’s exit status, it returns a 0-exit, indicating that it was successfully executed.
As a result, this script has two key applications that support it: one can wait for changes, and the other can make duplicates of this alteration in real time. What is needed in this case is a technique to connect the two tools so that rsync operates as soon as inotifywait detects any change.
Conclusion
Always make a backup of your data using every available method. A certain technique to ensure your data’s safety from any hardware problem is the approach I suggested using rsync.
In this article, you’ve learned how to use rsync to backup your data on an Arch Linux system. Once more, it’s best to practice the steps virtually before attempting the actual backing up of your drive.
If this guide helped you, please share it. 🙂