Chapter 7. Backup and Recovery with rsync and cp
You know you need to make good backups of your computer files and to test them periodically to see if you can restore your files. But how do you do this on Linux? Fear not, for backups and restores on Linux are quite understandable, and your backup files are easy to search and restore.
It is helpful to have a couple of USB sticks for practicing the commands in this chapter and a few directories full of files that you won’t mind losing, should anything go wrong.
We will use rsync and cp. Both are essential Linux tools, and you can count on them being well maintained and available.
cp is the copy command included in the GNU coreutils package, which is installed by default on nearly every Linux distribution. cp is for simple copying. It may be all you need to maintain regular backups.
rsync is an efficient file-transfer program, and its main purpose is keeping filesystems in sync with each other. When you use it for making backups, it keeps your local files in sync with your backup device. It is fast and efficient because it transfers only the changes in files. Unlike a lot of backup software, which never want you to delete anything, it even mirrors deletions. Because of these features, rsync is the tool of choice for updating and mirroring user home directories, websites, git repositories, and other large complex file trees.
There are two ways to use rsync over a network: over SSH, for authenticated login and transport, or by running ...
Get Linux Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.