Tuesday, March 20, 2007

How to Backup Data on Ubuntu Linux Using Simple Backup Suite

UPDATE: I've since decided to stop using the following SMB/CIFS mount to backup my data and instead am using the NTFS-3G driver and my local Windows hard drive since it is, well, local and thus faster. If you are in a similar situation and would prefer that to SMB/CIFS, then skip down to the "Backups" section after reading this post.


This document assumes you already have Ubuntu Linux up and running and is based on Ubuntu Edgy 6.10, though assuming they keep the Simple Backup Suite available in future versions I see no reason why this won't continue to work on newer versions.

First off, I chose to store my data on a remote Windows SMB/CIFS share. Why? Well, for one, I wanted my files on a system other than my Ubuntu Linux PC for obvious reasons. Second, the Windows PC is the only other computer in my home, so my options were limited. The following are the steps I used to set things up for this scenario:
  • In order to mount a remote SMB/CIFS share (the Windows PC) you need to make sure you have the "smbfs" package installed. Do this using either apt-get or Synaptic.
  • Next, unless you want to mount the remote filesystem by IP address or you have a DNS server in place, you should probably add the remote system to your /etc/hosts file.
  • Next, you need to either pick an existing directory (such as /mnt) or create your own directory where you will mount your remote SMB/CIFS filesystem.
  • Rather than doing a manual mount command each time the system boots, we will set it up to mount on startup each time. To do this, you need to place an entry in your /etc/fstab file as follows:
//remote_computer/sharename /mount_dir cifs credentials=/path_to_credentials_file,uid=username,gid=groupname,file_mode=0644,dir_mode=0755 0 0
  • Note that the above path is one long line.
  • Most of the line we just added is straightforward, however let me explain a bit. First is the path to the remote computer's filesystem, the Windows PC in my case. Then after the space is the location where you want to mount the remote filesystem, /mnt/windowsPC for example. Following that is the filesystem type that we are mounting, CIFS in this case, then you have the credentials file (created in the next step). The "uid=" part is only needed if you want to force the files and directories on the mounted filesystem to be owned by a particular user account. The "gid=" is the same thing, except this defines the group name that the filesystem will be owned by. The "file_mode=" sets the file mask while "dir_mode=" sets the directory mask. Click here for more info on the numbers that follow these parameters if you do not understand them. As for the final two 0s (zeros) on the line, they control how the "dump" and "fsck" programs work on this file system. I'd stick with the 0s (zeros) until you read through the man page for "fstab" (type man fstab to read it).
  • Finally, we need to create a credentials file at the location we pointed to in /etc/fstab. To do so, simply populate the file with two lines as such:
username=an_account_with_permissions_on_remote_filesystem
password=password_to_above_account
  • I named my filename .smbpasswd and also created a separate Windows account on my remote computer that I only use for this particular share (the account is just a regular user account on my Windows XP computer and has "modify" rights to the share I am mounting to keep it somewhat secure). I put a strong and random password on this account and entered it into the .smbpasswd file accordingly.
  • Now, you may notice that we just put a username/password in a clear text file. Obviously this is bad, which is why I used a separate, non-admin account for this. On top of that, we will change the permissions on this file so that only the necessary user (my Linux account in this case) has read/write permissions by typing chmod 600 .smbpasswd. When the paths in /etc/fstab are mounted, it is done by the root user, which can still read this file. Coincidentally, this fact is also a good reason to use the "uid=" and "gid=" parameters above in the /etc/fstab file so that the mounted filesystem is not owned by root only.
  • Finally, either reboot your system to test things out or type mount -a to mount everything in the /etc/fstab file.
  • Assuming everything above worked, you should now have a remote SMB/CIFS filesystem mounted and should be able to read/write files to/from it.
  • Attribution: Pretty much everything I've documented so far I learned from this site.
Backups:
  • Now that the remote share is set up, we can install/configure the backup software. As mentioned earlier, I chose to try out the Simple Backup Suite.
  • To install Simple Backup, just install the "sbackup" package.
  • After installation, you should see two new entries on your System --> Administration menu--"Simple Backup Config" and "Simple Backup Restore."
  • Select "Simple Backup Config" to configure the backup.
  • There are different ways to configure the backup and rather than go through them all, I will explain what I did and refer you to this site, which is straight from the Ubuntu Edgy Starter Guide section on backing up Ubuntu. In addition to Simple Backup, it also has a link to Dar and Kdar if you are interested (I did not try these out).
  • On the first tab (General) of Simple Backup I selected "Custom" as the recommended settings would not accomplish what I needed. "Manual backups only" also would not accomplish what I needed, which was to backup all my data automatically.
  • On the second tab (Include) I removed all directories except for /etc and /home. The first directory (/etc) is good to backup because it contains lots of configuration files for Ubuntu and /home of course contains the users' home directories and generally all the users' data. This is definitely the case for me.
  • On the "Exclude" tab I left all the default paths the same and even added one--the directory that contains my BitTorrent downloads. I only exclude that because it often contains large files that I only keep for a short while and are generally not something I consider crucial if my hard drive died. Plus, the hard drive I'm backing everything up to isn't all that big, so I need to save disk space where possible.
  • On the same tab, there are side tabs on the left side of the window. The "Paths" tab I just referred to in the previous step, but the next side tab is "File Types." I removed all the default file types as I have data of those types and want to back it up. I'm not sure why MP3 files are excluded by default since I'm sure the majority of users would be quite upset to lose their music library if their hard drive died.
  • On the next side tab, "Regex," I did not remove anything. It appears to exclude the directory storing auto-generated thumbnails of images from viewing in Nautilus, the Trash directory, and the Firefox cache directory. I don't care to save any of this stuff and you probably shouldn't either.
  • On the "Max size" side tab, I simple unchecked the "Do not backup files bigger than..." check box because I don't care how big my files are. If they are in my list of included directories, then I want them saved regardless of size.
  • Next, on the "Destination" tab I selected "Use custom local backup directory" and selected the path to my recently mounted SMB/CIFS remote filesystem. This selection is a bit misleading since it says it is a local directory when in reality it doesn't have to be. The default selection is truly local, however, so keep in mind that storing your backup files there won't help you in the event of a hard drive failure if that directory (/var/backup) is not mounted to at least a different physical hard drive.
  • On the "Time" tab, you can select whether or not you want to schedule backups to run automatically. My initial settings (I may change these in the future depending on how things work out) were to do a backup every day at 3am and to do a full backup at least every 14 days. I'd prefer to do a full backup every week, but I don't think my remote Windows PC that's hosting my SMB/CIFS share will have enough disk space to accommodate this.
  • Finally, the last tab (Purging) let's you set how long to retain your backups. Once again, I'm starting out by selecting "Logarithmic" (the default and recommended setting by the application) and will change it if necessary (e.g. if my Windows PC runs out of disk space too early I will probably just do the "Simple cutoff" option and set the number low enough) down the road.
  • When done setting your options, simply click the "Save" button and the settings are saved and backups should run at your scheduled time if you've configured it as such. You also have the option to kick off a manual backup job to test things out.
  • Simple backup will run a full backup the first time it runs and then do incremental backups each time until the number of days passes that you set on the "Time" tab for full backups to occur.
Restores:
  • Now that you've backed everything up, you might want to test the restore function. Just click on the "Simple Backup Restore" shortcut on your "Administration" menu to get started.
  • The first thing to do is to select your "Restore Source Folder." The default choice should point to wherever you told Simple Backup to store your backup files. In my case this is the remote SMB/CIFS filesystem we mounted in the first part of this post.
  • Next, choose from the list of available backups. Obviously if you've had a complete loss of data you'll want to pick the most recent full backup, and then restore each incremental backup after that.
  • The following screen shot is an example of a restore (the /etc/X11/xorg.conf file in this case):
  • As you can see, there are two restore options--"Restore" and "Restore As." The first will restore the file to its original location. The second let's you pick an alternate location if you like. This is the one part where I found a bug in the software. If you try to browse for the alternate directory and click "Open" it still tries to restore it to the original location (it'll ask you if you want to overwrite the file if it already exists). So, if you truly want to restore to an alternate location, you'll have to just type it in the "Name" text box as shown in the next screen shot:
That's pretty much it for backups and restores on Ubuntu. One thing I've noticed is that the daily incremental backups are larger than I thought they'd be considering I didn't change any of my own data. However, the hidden directories such as .gconf, .gconfd, .nautilus, etc. all have files that frequently get updated. I may decide to exclude these from the backups soon because so far, my first two incremental backups have taken up 55-80MB of space each, so that will likely add up quickly and most of that data would be regenerated in the event of a hard drive crashing and having to reinstall Ubuntu on a new one. But there might be a configuration file that I'd want in there some day, so until disk space becomes an issue, I'll probably leave them be.

Finally, one thing to note is that the Simple Backup configuration file is named /etc/sbackup.conf in case you need to restore it some day.