Skip to main content

Backup and Recovery Using Rsync

Hands-On Lab

 

Photo of

Training Architect

Length

00:30:00

Difficulty

Beginner

This hands-on lab is designed specifically to show how a free tool, rsync, can be used to perform backup and recovery operations from a local system to a remote one. Rsync derives its name from its main task: remote synchronization. It is commonly used as a backup or mirroring tool, but can also be used to sync files either remotely or locally. To view the man page for rsync, click here.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Backup and Recovery Using Rsync

Introduction

This hands-on lab is designed specifically to show how a free tool, rsync, can be used to perform backup and recovery operations from a local system to a remote one. Rsync derives its name from its main task: remote synchronization. It is commonly used as a backup or mirroring tool, but can also be used to sync files either remotely or locally. To view the man page for rsync, click here.

The Scenario

We've been tasked with testing a solution to help our organization ensure that backups are performed on one of the file servers. We decided to try rsync, an open-source tool, since this will allow us to back up only the directory we need.

Client1 is the file server, and Server1 is the backup location that we want to store this directory on. Both systems will be used during this lab, so we should be logged into each of them right off.

Logging In

On the hands-on lab overview page, use the credentials provided and log into each of the machines, Client1 and Server1 with SSH.

Install Rsync

Install Rsync on both Server1 and Client1:

yum install rsync

Note: To use the above command without adding sudo, you will need to be the root user. If you do not elevate privileges to root, you will need to add sudo to the beginning of the command. Either way is fine.

Create a Directory for Backup on Client1

Create a new directory called files4backup:

mkdir /home/cloud_user/files4backup

Create Two Files in files4backup, tps_report1.txt and tps_report2.txt, Which Will Be Used to Verify That the Backup Was Successful Later On

Create two new text files, tps_report1.txt and tps_report2.txt:

touch /home/cloud_user/files4backup/tps_report1.txt
touch /home/cloud_user/files4backup/tps_report2.txt

Using rsync, Copy the Files from Client1 to Server1

Run the following command:

rsync -avz /home/cloud_user/files4backup/ cloud_user@10.0.1.10:/home/cloud_user/files4backup/

You may be prompted for a password. If so, use the one provided on the lab page for cloud_user

Verify that the contents of the files4backup directory were copied from Client1 to Server1. This can be accomplished by logging into Server1 and running the following commands:

cd /home/cloud_user/files4backup
ls

The two files that we created in in the last step should be present.

OPTIONAL - Modify tps_report1.txt and Verify That the Changes Are Carried over after Performing Another Copy to Server1

On Client1:

Open the tps_report1.txt file:

vim /home/cloud_user/files4backup/tps_report1.txt

Add some text to the file and save it, then perform another remote copy:

rsync -avz /home/cloud_user/files4backup/ cloud_user@10.0.1.10:/home/cloud_user/files4backup/

Back on Server1:

Open the tps_report1.txt file to verify that the changes were carried over:

vim tps_report1.txt

Delete a File in the files4backup Directory on Client1 and Restore It from Server1

On Client1, remove tps_report2.txt:

rm /home/cloud_user/files4backup/tps_report2.txt

Verify that it's gone:

cd /home/cloud_user/files4backup/
ls

We should only see tps_report1.txt in there.

From Server1, run a remote copy of our files4backup directory back to Client1:

rsync -avz /home/cloud_user/files4backup/ cloud_user@10.0.1.11:/home/cloud_user/files4backup/

Back on Client1, verify that tps_report2.txt exists:

cd /home/cloud_user/files4backup
ls

Conclusion

Rsync is a great backup and recovery tool, and in this lab we've gone through the routine of using it to back up and recover data across machines. Congratulations!