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) ...

Get Mastering UNIX® Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.