view · edit · attach · print · history

My Linux Backup

This article describes how I back up data in my house. There is nothing more important you can do with your computer than keep your data backed up, so I go through it step by step. There are lots of other ways to do this, but here is how it works in my house.

I have two Linux servers, Sagan and Hubble. Both are running Ubuntu Linux. Sagan is the main server, Hubble is the backup. I don't currently have a way of knowing when there is a problem with this server, it is something for me to work on..

Everyone in the house has an account on Sagan, and I tell them to save their stuff there. If it isn't saved there, I don't want to hear any whining when things go wrong.

I am using rsync for backup, so SSH must be installed on both servers:

sudo apt-get install ssh

There are many ways for backups to fail, so whatever solution you use for backups, you must have some way to check and see if it is working. While writing this article I realized that Hubble was down - the power went out the day before and it was not running. I went downstairs and hit the power button so I could keep writing the article.

Another thing I want to mention is that it is a good idea for servers to have fixed IP addresses. You always want to be able to find your server even if something else breaks. Ubuntu does not make it easy to set up a fixed IP address, so it is best to reserve an address on your router. Read Fixed IP Address for details.

On Sagan, I configured Samba to act as a file server. I have several folders that I back up, for purposes of this article I will cover /home/igor and /home/pictures. For more information on basic Samba configuration, see Basic Samba Configuration.

On Hubble, I created a folder called /home/backup. I want /home/backup/igor and /home/backup/pictures to mirror the corresponding folders on Sagan. Always make sure your backup folders are obviously backup folders - if I just had /home/igor on Hubble it would be easy to mistake it for the real folder (yes I speak from experience)..

I created an account called "igor" on both servers with the same password. It would be cleaner to set up one server as the domain controller, and put the other server on the same domain, so that all user accounts would be configured in one place, but if there are only two servers it is not necessary.

Since the backup has to be automated, I don't want to have to enter a password each time. I configured ssh on Hubble to not require a password using instructions here:

I could have set up the backup script to run on either Sagan or Hubble. I chose to run the backup script on Hubble and pull the files from Sagan, this way the backup server is completely responsible for the entire backup operation.

The rsync commands I use to run the backup are:

  • rsync -av igor@sagan:/home/igor /home/backup > ~backup.log
  • rsync -av igor@sagan:/home/pictures /home/backup >> ~backup.log

You should run these commands manually to make sure they work, and then check the results. The first time it will take a while, but after that rsync is very fast as it only copies things that have changed.

The command to set up a scheduled job under linux is "crontab". Type crontab -e in order to edit the cron table. Remember that "sudo crontab -e" will edit root's crontab, while "crontab -e" will edit your crontab - either is fine as long as you know the difference. You must have authority to access all the files you will be backing up. In my case igor is a member of group users, and all files on /home/sagan also belong to group users. If you don't have the correct permissions, you will see errors from the rsync command above, and will need to resolve them.

Crontab has 6 columns - minute, hour, day of month, month, day of week, and command. You can put in a comment starting with a #, and in every crontab file I use, the first line is a comment reminding me of what each column does. I want my backups to run at 2AM, so I have the following in my crontab:

# m h dom mon dow command

00 02 * * * rsync -av igor@sagan:/home/igor /home/backup/ > ~/backup.log 10 02 * * * rsync -av igor@sagan:/home/pictures /home/backup/ >> ~/backup.log

I enter this by typing crontab -e, entering the commands above, and saving the file. In the morning, I should have a file called backup.log in my home folder, and I can look at it to check if the backup worked.

It would be useful to set up something to email the backup file to myself, or even email it only if there are errors. For more information, see Mail Logs?.

If you can go through the steps above, and see the backup.log in the morning, then you have successfully set up a backup!

view · edit · attach · print · history
Page last modified on October 15, 2011, at 06:57 AM