No data loss. Secure your valuable data via the Linux command line. We use the command
rsync for this and have even found some nice optional graphical interfaces for it.
There are many ways to back up your files. We wanted to show you a robust, flexible and reliable way to protect your data. We've selected
rsync because it has well-known algorithms that calculate the differences between files in the source and destination directories. Only the differences between two versions of a file are transferred, not the entire file, if this can be avoided.
If this efficiency goes along with the solid track record of performing file copies and directory synchronization since the mid-nineties,
rsync is a perfect candidate for backing up from the Linux command line.
In addition, there are independent software programs that act as a front-end to
rsync . They provide graphical user interfaces (GUIs) for
rsync which may be easier for some users to use.
The easier and faster a backup can be performed, the more likely it is. [1
To back up your data to an external hard drive, the hard drive must be enabled and accessible to you. If you can write on it, you can also
rsync . In this example, an external USB hard disk named SILVERXHD (for "Silver eXternal Hard Drive") is connected to the Linux computer. It was automatically provided by the operating system.
You must know the path to the drive. In GNOME, open the Nautilus File Browser and locate the name of the drive in the sidebar.
Hover the mouse over the name of the external drive, and a tooltip will show you the path to the drive.
In this example, the tooltip tells us that the mount point for the file system on the external drive is "/ media / dave / SILVERXHD". Navigate to the external drive Drive and open a terminal window there. Use the command
pwd to print the path to the terminal window.
Copying content from the source directory
rsync to copy the contents of a directory into it Use the following command as the backup destination:
-r (recursive) causes
rsync to copy all nested subdirectories and their contents. Note that at the end of the word "SILVERXHD" there is a slash "/", but it will be broken in the next line of the screenshot.
rsync -r / home / dave / Documents / / media / dave / SILVERXHD /
The File copy is executed and you are returned to the command prompt.  If we look at the external USB drive, we see that the directories in the Documents directory have been copied to the root of the external drive.
Copy The source directory and its contents
If you wanted to copy the document directory and to the external drive, remove the " / "at the end of" / home / dave / Documents ". at the command line as follows:
rsync -r / home / dave / documents / media / dave / SILVERXHD /
To avoid confusion, I removed the two previously copied directories from the external drive before executing this second command.
When we finish the second copy and look at the external drive again, let's look at that, see the Documents directory has been copied. The content is in this directory. You are not in the root directory of the external drive.
Copy to a specific destination directory
Add the following to copy to a specific directory on the target disk The name of the directory to the destination path. Suppose we want to copy the contents of the / home / dave / Documents directory to a directory called backups on the external drive.
We do this with the following command.
rsync -r / home / dave / Documents / / media / dave / SILVERXHD / backups /
On the external drive, we see that the backup directory has been created, and this directory contains the contents of the / home / dave / Documents directory.
Keeping file ownership and permissions
-a (archive) option to Keep file attributes such as modification date, file ownership, access permissions, etc. for copied files. Symlinks and special block files.
rsync -ra / home / dave / Documents / / media / dave / SILVERXHD / backups /
Using Verbose Mode
-v (verbose) forces
rsync to list the files to be copied.
rsync -rav / home / dave / Documents / / media / dave / SILVERXHD / backups /
When the copy is complete, a summary of the backup appears.
- Sent : The bytes transferred to the destination.
- Receive : The bytes received at the host.
- Bytes / sec : is the effective transmission rate.
- Total Size : Represents the size of the data that would have been sent if you had not used rsync . On subsequent runs of
rsynconly the file differences are transferred. This number represents the data that did not need to be transmitted .
- Acceleration : This is the ratio between the amount of data that had to be sent and the total amount of data that was transmitted there. If
rsyncneeds to completely copy all the files (for example, the first time you run them), the speed is 1.0. The next use of
rsyncwill optimize the transfers. Only the differences between the files are sent, not the entire files. Files without changes are ignored. The acceleration count represents the ratio between the small amount of data that needed to be transferred and the total size of the files.
Using the Progress option
-P (progress) Causes
rsync generates a small progress report after copying each file.
rsync -raP / home / dave / Documents / / media / dave / SILVERXHD / backups /
The information provided can be viewed between each copied file.
The information provided is:
- byte size : data transferred for this file.
- Percentage : Percentage of transferred files.
- B / s : data transfer rate.
- Remaining time : Estimated time remaining to transfer this file.
- xfr # : The number of transferred files. Previous error.
- to-chk : The number of files that must be verified and verified by the optimization algorithms (compression) option. This compresses the file during the transfer, but does not save the file compressed in the destination directory.
The compression option does not provide significant benefits for many small file transfers. For collections of larger files, this can significantly reduce transmission time.
We also use the option
rsyncdeletes partially transmitted files caused by network errors or other interruptions. The option
rsyncto leave the partially transferred files on the target. When the net time
rsyncis executed, the parts of the partially transferred files do not have to be retransmitted.
Note that you may not want to use this option if there is a risk of someone confusing the file. Partially transferred files for completely transferred files.
rsync -ravz --partial / home / dave / Documents / / media / dave / SILVERXHD / backups /
In our example, the benefits are marginal.
The acceleration ratio has been improved but by two hundredths of a percent! In a real-world scenario, your speed improvements are more impressive.
Using rsync over a network
So far, we have selected an external USB drive as the destination. Use the path to this location on the command line to use a network location as the backup destination. The network examined in this article has a Network Attached Storage Device (NAS).
You can use the same trick as before to determine the path to the NAS by hovering over the connection to this device in Nautilus.
There are no special options for backing up in a network. These are all options we have already used.
rsync -ravz --partial / home / dave / Documents / / media / dave / NAS / dave / backups /
There is no difference in the format of the output.
 Not surprisingly, the number of bytes / sec improves significantly.
If we run
rsyncagain, we can see that no files need to be transferred because no changes have been made. However, some bytes are still being transferred back and forth. This is the amount of data that must be transferred to compare the file list on the destination with the file list on the source.
The acceleration ratio is an order of magnitude better in this case. In practice, your performance ratios are somewhere between our two pseudo-artificial readings.
Using rsync over SSH
rsyncsupports backing up over an SSH connection. We need to specify the name of the user account and the SSH location on the command line. We use a network name here, but you can also use an IP address.
Note the ":" between the SSH connection details and the start of the network path on the remote destination.
rsync -ravz - -partial / home / dave / Documents / firstname.lastname@example.org: /home/dave/backups/
You will be asked for the password of the user account on the remote computer . This is not your password on the source computer.
The backup is completed as usual. Throughput is not as high as a normal network connection due to the encryption and decryption that takes place in the secure shell connection.
Automating Your Backups
By adding entries to your crontab file, we can easily create automated backups.
We set up an automatic backup that runs every day at 4:30 (if the computer is on at that time) course) , The syntax for the command
rsyncdoes not change at all.
Ctrl + O writes your changes to the file. and Ctrl + X close the editor
RELATED: Scheduling Tasks on Linux: An Introduction to Crontab Files
Putting a Friendly Face on Rsync
Persons less familiar with the command line , can use one of several programs that set a graphical user interface to
rsync. Two good examples are luckyBackup and Grsync. In both programs, many of the
rsyncoptions can be selected through the user interface.
Grsyncprogram focuses on being a visual wrapper for
rync. , It provides easy access to the options
rsyncand adds only a limited set of new functions.
The [19459009ProgramLuckyBackup is much more than a simple wrapper for
rsync. It is a backup program used behind the scenes
rsync. For example,
luckyBackupcan create multiple "snapshots" of your backup. You can then return to the versions of the files in each of the snapshots.
How to Install Grsync
Grsyncin Ubuntu Use this command:
sudo apt-get grsync install
How to Install
GrsyncUse the following command in Fedora:
sudo dnf install grsync
 To install
Grsyncin Manaro use the following command:
sudo pacmanc -Syu
luckyBackupin Ubuntu, use the following command:
sudo apt-get lucky-install
So ins install
luckyBackupUse the following command in Fedora:
sudo dnf install luckybackup
In Manjaro you need
luckyBackupfrom the Arch User Repository (AUR). You can do this with the package manager
Do not risk it, backup your data. Backups are absolutely important. Secure frequently, in many places and on different media. Once set up,
rsynccan do all this for you.