How To Use rsync Command To Backup Directory Under Linux

How To Use rsync Command To Backup Directory Under Linux

The rsync command is a powerful tool for backing up directories under Linux. It is a fast, efficient, and flexible way to copy files and directories between systems, and it is especially useful for transferring large amounts of data over a network.

To use rsync to backup a directory, you will need to specify the source and destination directories and any additional options you want to use. For example, to copy the /home/user directory to the /backup directory on the local system, you can use the following command:

rsync -avz /home/user /backup
Source:‮ual.www‬tturi.com

The -a option tells rsync to preserve the permissions, ownership, and other attributes of the files and directories being copied. The -v option tells rsync to be verbose and display a progress report, and the -z option tells rsync to compress the data being transferred.

To copy the /home/user directory to a remote system, you will need to specify the username and hostname of the remote system in the destination path. For example:

rsync -avz /home/user user@remote:/backup

This will copy the /home/user directory to the /backup directory on the remote system. You will be prompted for the password for the user account on the remote system.

You can use additional options to customize the behavior of rsync. For example, the --delete option tells rsync to delete files in the destination directory that are not present in the source directory. The --exclude option allows you to specify patterns of files or directories to exclude from the transfer. Consult the rsync documentation for a complete list of options.

It is recommended to schedule periodic backups using cron to ensure that your data is regularly backed up. This can be done by creating a script that contains the rsync command and scheduling the script to run at regular intervals using cron.

Created Time:2017-10-29 22:08:34  Author:lautturi