Rsync is a powerful tool for synchronizing files and directories between two locations. It allows you to transfer files efficiently and securely, and it can handle large amounts of data with minimal impact on network performance. In this article, we will show you how to use Rsync to mirror files on Rocky Linux.
- Before you can use Rsync, you need to make sure that it is installed on your Rocky Linux system. Run the following command to check if Rsync is installed:
rsync --version
If Rsync is not installed, you can install it by running the following command:
sudo dnf install rsync
- To use Rsync to mirror files, you need to specify the source and destination locations for the files. The source location is the location of the files that you want to mirror, and the destination location is the location where you want to store the mirrored files. For example, if you want to mirror the files in the
/home/user1/documents
directory to the/mnt/backup
directory, you can use the following command:
rsync -avz /home/user1/documents/ /mnt/backup/
This will transfer all the files and directories in the /home/user1/documents
directory to the /mnt/backup
directory, using the -a
(archive) and -v
(verbose) options to preserve file permissions and display the progress of the transfer.
- By default, Rsync will transfer all the files and directories in the source location to the destination location. However, you can use various options to customize the behavior of Rsync. For example, if you only want to transfer files that have been modified in the last 24 hours, you can use the
-update
and-times
options, like this:
rsync -avz --update --times /home/user1/documents/ /mnt/backup/
This will only transfer files that have been modified in the last 24 hours, and it will preserve the timestamps of the transferred files.
- In addition to transferring files, Rsync can also delete files in the destination location that have been deleted in the source location. To enable this behavior, you can use the
-delete
option, like this:
rsync -avz --delete /home/user1/documents/ /mnt/backup/
This will transfer all the files and directories in the source location to the destination location, and it will delete any files in the destination location that have been deleted in the source location.
- To transfer files securely over the network, you can use Rsync in combination with SSH. To do this, you need to specify the
e
(remote shell) option, followed by thessh
command. For example, if you want to transfer files from theuser1@192.168.1.100
server to the local/mnt/backup
directory, you can use the following command:
rsync -avze ssh user1@192.168.1.100:/home/user1/documents/ /mnt/backup/
This will transfer all the files and directories in the /home/user1/documents
directory on the remote user1@192.168.1.100
server to the local /mnt/backup
directory, using SSH to encrypt the data transfer.
In this article, we have shown you how to use Rsync to mirror files on Rocky Linux. Rsync is a powerful and versatile tool that allows you to transfer files efficiently and securely between different locations. You can use the various options available in Rsync to customize its behavior and tailor it to your specific needs. For more information and a complete list of options, you can refer to the Rsync documentation.