How to rsync your Ubuntu home directory to an external hard drive

This is not hard to do, but backing up my laptop is not something I do often enough to remember exactly how I did it the last time. Using rsync in this way is by no means specific to Ubuntu—but I imagine it might be particularly useful for Ubuntu users.

Setup

Plug in your external USB hard drive. Mine shows up with a mount point of /media/disk, so that’s what I’m going to reference below. If you’re only ever going to backup one computer, I’d recommend creating a directory on the drive called “backup” to separate your backup from any other files you might have or might want to put on it.

cd /media/disk
mkdir backup

Because at one time or another I’ve had multiple computers, I’ve tended to create directories named after the computer’s model number—x200 in the case of my Lenovo X200.

Backup

Here’s the command to backup your home directory to an external hard drive.

rsync -avz --delete --exclude=".*/" /home/username/ /media/disk/backup

Of course you need to replace username with your own username, and make sure /media/disk/backup actually exists. I don’t like copying over hidden directories (those that start with “.”) which is why I add --exclude=".*/". If you really wanted an exact mirror copy of your entire home directory, then just leave that out. Note: the slash (/) after your username is important to prevent a directory called username from being created in /media/disk/backup.

Here’s the actual command I use:

rsync -avz --delete --exclude=".*/" /home/jwatt/ /media/disk/x200

3 comments

name
blog (optional)
comment

Well, if you exclude .*/ then what is the point of having a backup of the home dir? Most of the programs put their config into dirs beginning with a dot.

In my experience I’ve found that moving a home dir from one install to another, complete with hidden files and directories, results in a broken user account.

Plus for me, it’s always been the data I create that’s the most important, not the program settings and etc.

monthchunks

license

Justinsomnia is licensed under a Creative Commons Attribution 3.0 License.

Please see my Attribution Policy for more information.