An old favorite for backing up is rsync. One big reason for this is that
rsync enables you to copy only files that have changed since the last
backup. With this tool, although the initial backup might take a long time,
subsequent backups are much faster. rsync is also highly configurable and
can be used with removable media such as USB hard drives or over a
network. Let’s look at one way to use rsync.
First, create an empty file and call it backup.sh:
Click here to view code image
matthew@seymour:~$ sudo touch backup.sh
Then, using your favorite text editor, enter the following command into the
file and save it:
Click here to view code image
rsync --force --ignore-errors --delete --delete-excluded --exclude-
from=/home/matthew-exclude.txt --backup --backup-dir=date +%Y-%m-%d
-av /
/media/externaldrive/backup/Seymour
Make the file executable:
Click here to view code image
matthew@seymour:~$ sudo chmod +x backup.sh
This command uses several options with rsync and puts them in a script that
is quick and easy to remember and run. You can run the script at the
command line by using sudo sh ./backup.sh or as an automated
cron job.
Here is a rundown of what is going on in the command. Basically, rsync is
told to copy all new and changed files (what to backup) and delete from any
existing backup any files that have been deleted on the source (and back them
up in a special directory, just to be safe).It is told where to place the backup
copy and is given details on how to deal with specific issues in the process.
(Read the rsync man page for more options and to customize to your
needs.)
Following are the options used here:
—force—Forces deletion of directories in the target location that are
deleted in the source, even if the directories in the destination are not
empty.
—ignore-errors—Tells —delete to go ahead and delete files even
when there are I/O errors.