Putting it all together: Writing an rsync backup script
Let's close this chapter with a Bash script that will not only prove to be very useful, but will also help you further your skills. The rsync
utility is one of my favorites; it's very useful for not only copying data from one place to another, but also helpful for setting up a backup job. Let's use the following example rsync
command to practice automation:
rsync -avb --delete --backup-dir=/backup/incremental/08-17-2018 /src /target
This variation of rsync
is the exact one we used back in Chapter 8, Sharing and Transferring Files. Feel free to consult that chapter for an overview of how this utility works. This example rsync
command uses the -a
(archive) option, which we've discussed before. Basically, it retains the metadata of the file, such as the time stamp and owner. The -v
option gives us verbose output, so we can see exactly what rsync
is doing. The -b
option enables backup mode, which means that if a file on the target will be...