You are on page 1of 4

Labs  RHEL Backup and Restore Assistant

RHEL Backup and Restore Assistant


Knowledge Type

Choose tool

 Tool rsync

Incremental backup with rsync

The rsync utility is commonly used to perform backup operations in Linux


because it can synchronize files and directories from one location to another.
The backup location for these files can be on either a local or remote server.

The syntax is:

# rsync options source destination

The following are examples demonstrating how to use rsync. For these
examples, root permissions are required for both the destination and source
servers. The example operations deal with common files such as
~/.ssh/id_rsa.pub and common folders such as /home/ and /.

1. Back up a single file

# rsync -v ~/.ssh/id_rsa.pub /backupfolder/

2. Back up the directory to a local directory


# rsync -zvr /home/ /backupfolder/

-z is to enable compression
-v verbose
-r indicates recursive

Use the -a parameter with the rsync command to preserve time stamp
and permission information during a sync.

# rsync -azv /home/ /backupfolder/

The -a option does the following:

Recursive mode
Preserves symbolic links
Preserves permissions
Preserves timestamp
Preserves owner and group

3. Synchronize Files From Local to Remote

rsync allows you to synchronize files/directories between the local and


remote system.

# rsync -avz /home/ username@remoteServer:/backupfolder/

To avoid entering a password when backing up files from a local to a


remote server, use the following instructions to set up ssh passwordless
login. A passwordless login is useful in situations where an rsync is
required without entering the password.

4. Include and Exclude Pattern during File Transfer

Rsync accepts a pattern provided to include or exclude files and


directories while synchronizing files.

# rsync --include 'p*' --exclude '*' -avz /home/ username@remoteSe

The following is an example of backing up a complete system with the


rsync command,
# rsync --exclude={/dev/*,/proc/*,/sys/*,/tmp/*} -aAXvz /* usernam

 Rsync accepts a pattern provided to include or exclude files and


directories while synchronizing files.

5. Remote shell for Synchronization

Use rsync -e ssh to specify which remote shell to use. In this case, rsync
will use ssh with port 12345.

# rsync -avz -e 'ssh -p 12345' username@remoteServer:/home/ /backu

6. Do Not Overwrite the Modified Files at the Destination

In most situations, if a file is modified at the destination location, we do


not want to overwrite the updated file with an older version from the
source.

The rsync -u option ensures that the newer version of the file is not
overwritten, even if it is present at the destination.

# rsync -avzu /home/ username@remoteServer:/backupfolder/

7. View the rsync Progress during Transfer

To view the progress of the file backup, use the --progress option to view
information such as how many files are copied, the copying speed, etc.

# rsync -avz --progress username@remoteServer:/home/ /backupfolder

8. Delete the Files Created at the Target

If a file is not present at the source but is present at the target, delete the
file at the target location during the rsync.

To remove a file, use the --delete option as illustrated in the following


example. This option ensures that any files not present in the source
directory are deleted from the target directory.
# rsync -avz --delete /home/ username@remoteServer:/backupfolder/

9. Do not Create New File at the Target

Use the --existing option with the rsync command to specify that only
existing files at the target location are updated and files missing from the
target are not created.

# rsync -avz --existing /home/ username@remoteServer:/backupfolder

10. View the Changes Between Source and Destination

Use the -i option to view the differences between the source and
destination versions of specific files or directories.

# rsync -avzi /home/ username@remoteServer:/backupfolder/

11. Do Not Transfer Large Files

Use the rsync --max-size option to specify the maximum file size for
transfers.

# rsync -avz --max-size='100K' /home/ username@remoteServer:/backu

BACK

Copyright © 2021 Red Hat, Inc.

You might also like