DISCOVER
X

How to Backup Your Latest Files on Raspberry Pi

June 16, 2013 11:03 pm Leave your thoughts
FacebooktwitterredditpinterestlinkedinmailFacebooktwitterredditpinterestlinkedinmail

A few posts ago, I talked about using the Raspberry Pi as an Open Atrium Server. On top of that, the article also explained the step by step way to backup the server’s database automatically every midnight. What was left to do however, was the file backup. As you know, with applications such as Open Atrium we will upload many of our files to the Raspberry Pi therefore we do not want to lose any of this file should anything happen to our Raspberry Pi.

The solution that I’m going to present today is a simple one, basically we will use the built-in rsync command to synchronize the files from any directory that we want to backup. In this article we will backup our previously installed Open Atrium server. The installation location is /var/www/openatrium/ and the USB key where we will do our backup is mounted under /media/dduckusb/. If you want to know how to mount the USB permanently, visit the Open Atrium article.

Our RSYNC Command

First, let’s construct our rsync command. Basically we want to be able to sync all the files from the openatrium directory and its subdirectories. We also want to be able to log the output details of each synchronization. The target backup directory is: /media/dduckusb/backup/atrium/ make sure you have created the destination directory.

The option –r tells rsync to check the subdirectories too while –v tells rsync to output the details of the last synchronization run. Now normally, when we want to backup we would just use the option -a which is the archive mode; however since we are backing up to a FAT32 USB stick we can’t use some of the operations required by the archive mode.

Make it Run Automatically

Before doing this make sure you test the rsync command to see if it works on your system.

In order to make sure we can save the output of the last run, we need to tell the command to output to a file, in this example we will make it output to /media/dduckusb/backup/atrium.log. Therefore our command looks like:

We then add this command to our crontab.

On the editor add our rsync command with the desired time. My configuration looks like:

Your Files Will be Synced

That’s it, your Raspberry Pi is scheduled to keep a synchronised copy of your working directory in an external USB drive. Now you can be a bit relaxed knowing that you have your latest files backed up in the USB key. Next time we’ll show you some simple ways to enhance this backup method.

FacebooktwitterredditpinterestlinkedinmailFacebooktwitterredditpinterestlinkedinmail
Tags: , ,

Categorised in: ,