April 26, 2019

Linux Backups For Real People, Part 2 - page 2

Single-User Backups

  • November 8, 2007
  • By Carla Schroder

Using the backup device naming examples from last week's article, let's make a test backup to a USB drive of any kind. Plug it in, and then copy a couple of directories to it using this command. Remember, in part 1 we formatted the backup drive in FAT16/32, so the rsync options are special to the FAT filesystems. In this example I backup my finances and configs directories, using the full absolute path names:

$ rsync -rlvt --modify-window=1 ~/finances ~/configs /media/BACKUP1

The tilde, ~, is a shortcut for home directory. You'll see filenames whiz by, and then a summary:

sent 8306732 bytes  received 1270 bytes  3323200.80 bytes/sec

total size is 8301576 speedup is 1.00

Now open /media/BACKUP1 and admire your backed-up files. They look like normal files, which they are, which you can view and copy like any normal Linux files.

Mind your trailing slashes! Notice there aren't any, so I'll end up with /media/BACKUP1/finances and /media/BACKUP1/configs. If I named finances/ and configs/ instead, then I would get /media/BACKUP1 without the two directories, but only the files that were in them.

Now try a cool thing: hit the Up arrow to display your rsync command again and hit enter to re-run it. You'll see something like this:

$ rsync -rlvt --modify-window=1 ~/finances ~/configs /media/BACKUP1
sent 1582 bytes received 20 bytes 3204.00 bytes/sec
total size is 8301576 speedup is 5182.0

Notice the difference in the "sent" values. This shows that your rsync incantation worked correctly and transferred only changes on the second run.

The -r switch means recursive; -v is verbose, -l copies symlinks, -t preserves the modified times, and --modify-window=1 allows for a 1-second difference in the modified times between the original and copied files. The last three options are necessary hacks for FAT16/32. If you leave out the -t switch rsync will re-copy your files instead of transferring only changes. FAT16/32 represents times with up to two seconds' resolution, so you need the --modify-window option to allow for this.

rsync has a --dry-run option which you should always use when you're not sure if you have it right. This shows you what will happen without actually doing anything.

Most Popular LinuxPlanet Stories