O'Reilly logo

Mastering UNIX® Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus, Second Edition by Randal K. Michael

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER7

Using rsync to Efficiently Replicate Data

We use rsync as a faster option for copy (cp), remote copy (rcp), secure copy (scp), file transfer protocol (ftp), and secure FTP (sftp). We can use rsync to copy local files as well as to copy files between the local machine and a remote machine. However, rsync does not support copying files between two remote machines. The reason that rsync is faster than cp, rcp, and scp is that it uses the rsync remote-update protocol, which greatly speeds up file transfers when the file already exists on the destination server, for certain file types, and offers the option of compression. The rsync remote-update protocol uses an efficient checksum search algorithm that allows rsync to transfer only the differences between two sets of files, whether locally or remotely, across a network connection. Adding the -z switch to rsync compresses the files, which offers even faster file transfers.

NOTE rsync must be installed on both machines to transfer files remotely.

In this chapter we are going to look at the syntax to transfer files from a local machine to a remote machine, transferring files from a remote machine to the local machine, copying files locally, and using compression. Then we will study a simple, generic shell script to transfer files in archive-compressed mode. The final script is a pretty complicated shell script that I use to move Oracle data from a master database server to two remote Oracle OLTP (online transaction processing) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required