Using a Raspberry Pi to synchronize data

Lead Image © Dietmar Hoepfl,

In Sync

The Raspberry Pi is not powerful enough to support fully mature network storage. In situations involving smaller amounts of data, however, the little computer shines as a flexible data hub.

The old Microsoft motto of "a PC on every desk" has been obsolete for a while now. In fact, the myriad of intelligent devices is ever increasing in size. As a consequence, the need for data exchange solutions is growing as well. In today's world, the magic phrase is data synchronization. An important issue in synchronization is that there are many possible connections among just five devices, such as a server, desktop, laptop, tablet, and smartphone. Thus, it makes sense to have a central synchronization server replace point-to-point connections so that data exchange from one device to another can occur asynchronously (Figure 1).

Figure 1: A central hub for synchronization is necessary to maintain consistency among data sets that exist across various devices.

Access to the hub is always available, but not access to the individual devices. Moreover, you don't have to deal with different connections, and the devices don't have to go online at the same time for an exchange of data to take place. The data exchange hub therefore should run on a computer that is as efficient as possible in terms of power and heat generation. As a mini-PC, the Raspberry Pi is ideal for serving as a foundation upon which to build a home synchronization server. (See the box called "How Much Server Is Needed?")

How Much Server Is Needed?

Today, many households run Network Attached Storage (NAS) to provide file storage and, increasingly, cloud services. This type of system can also take care of synchronization tasks so that a separate sync server is no longer needed.

If the NAS runs on a proprietary operating system, or you only turn it on as needed because of power usage issues, then a small computer can be used to fill the gap. A small computer does not need high read and write performance because typically only small amounts of data are transferred over the connection during synchronization.

All of the services described here function easily on the Raspberry Pi and with a device like the mini-router TP Link MR3020 together with a USB stick. The advantage gained by using a TP Link device is that it can be used as a mobile device and only needs about 1  watt of power during operation. The disadvantage would be that a TP Link runs about four times slower than the Raspberry Pi.

An Alternative to Dropbox?

Dropbox has become almost synonymous with the notion of cross-platform data synchronization. For those who don't want to hand over the task of synchronization to a host provider, freeware alternatives like ownCloud [1] or Seafile [2] can be used. Both of these solutions run on the Raspberry Pi [3] as well. However, the Dropbox model of keeping all data on all participating devices synchronized is not always a suitable solution.

For example, Dropbox fails completely if the synchronization situation involves data that is usually kept in a database. This means that synchronization of Firefox data, address books, or appointment calendars would not work with Dropbox. Situations also come up in which services other than Dropbox are easier to use. Dropbox does not let you synchronize folders or files on just some of the participating devices; instead, the synchronized data is sent to all of the devices. For example, if you only want to show images that have been edited and reduced in size on your smartphone, then you won't need the altered images on something like a PC.

The Rasp Pi can run different sync solutions in parallel. The different solutions will not get tangled up, and resource use is not so large that it overwhelms the mini-PC.

Preparatory Work

A pared-down Raspbian System serves as the starting point for the solution that is introduced in this article. Deinstallation of all unnecessary packages significantly reduces the space required for installation to less than 1GB. This is about one third of the storage required for the current standard Raspbian distribution. As a result, there is enough storage space for exchanging data. However, to follow the steps in the article, I recommend starting with the standard version of Raspbian.

The Rasp Pi needs a working web server that includes PHP for two of the solutions. To start the process of turning the Rasp Pi into a hub, you should install the necessary packages with root rights using the script from Listing 1. I chose the lightweight web server Lighttpd. Raspbian has alternatives like Apache or Nginx that work the same.

Listing 1

Installing the Necessary Packages

# Install webserver
apt-get update
apt-get install lighttpd
# Basic PHP5 installation plus cache
apt-get install php5-cgi php-apc
ln -s /usr/share/doc/php-apc/apc.php /var/www/
lighttpd-enable-mod fastcgi-php
/etc/init.d/lighttpd force-reload
# System information via PHP
apt-get install phpsysinfo
ln -s /usr/share/phpsysinfo /var/www/status
# Set up access rights
chown -R www-data:www-data /var/www

You do not necessarily need the last package phpsysinfo. However, it does allow you to know with one quick look whether the installation has worked. All you have to do is point your browser to the URL http://<RasPi-IP>/status (Figure 2). For this article, I assume that the server only runs on the home network. Therefore, you won't need a secure connection via HTTPS.

Figure 2: One glance at the status page of Phpsysinfo reports system status and gives you information about the web server.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content