If you have two computers, you might want to synchronize data between the two. For example, if you have a laptop, you might want to transfer the files in your Documents folder to the main PC (and vice versa). You could do this manually by creating a network share, but it’s much better to do it automatically, with just a single click.
There are a variety of ways of synchronizing files under Ubuntu, and indeed, this is the kind of task that Linux excels in. However, perhaps the most fuss-free method is to use a program called Unison (or, actually, Unison GTK, which adds a graphical front end to the Unison command-line program; throughout I refer to the whole thing as Unison for simplicity). Unison uses built-in Linux tools to sync files but hides everything behind a friendly user interface.
The following are the steps required to sync the Documents folders on two separate computers using Unison. Before following these steps, ensure each computer has the correct time. This is essential because synchronization will fail otherwise.
These instructions make reference to a desktop PC and laptop computer but could be any two computers capable of running Ubuntu (or indeed any computer with Linux installed that can run Unison):
- On the desktop PC, use Synaptic to install the unison-gtk package. Meanwhile, on the laptop, use Synaptic to install the openssh-server and unison-gtk packages. As you might have guessed, Unison uses the SSH program in the background to provide the file transfer conduit but you won’t come into direct contact with it.
- Once installed on the desktop PC, Unison can be found on the Applications —> Accessories menu. When it starts, a wizard will walk you through creating an initial profile. The first step is to enter the folder on the desktop PC that you want to synchronize. Click the Browse button, and then locate your Documents folder. Click OK to close the file-browsing dialog box and OK again to move onto the next step of the wizard in Unison.
- In the next step, you must tell Unison which folder you want to synchronize with on the laptop. In the Directory text field, type Documents again. There’s no need to precede it with /home/username because Unison will automatically log into the laptop’s /home/ folder each time it synchronizes.
- Click the SSH radio button. You’ll now need to find the IP address of the laptop. This can be done by moving over to it, right-clicking its NetworkManager icon, and selecting Connection Information. Then look in the dialog box that appears for the line that reads IP Address. Type what you see (four numbers separated by dots) into the Host text field back on the desktop PC.
- In the User text field, still on the desktop PC, type the login name you use on the laptop. Then click the OK button.
- You’ll immediately be told that the laptop computer is being contacted. Then a dialog box will pop up telling you that the “authenticity of host can’t be established.” This is fine. Just type yes to continue, and hit OK.
- You’ll then be prompted for the login password on the laptop. Type it, and then click OK.
- After this, you’ll see a scary-looking warning dialog box saying that “no archives were found for these roots.” Don’t worry. This appears because this is the first time you’ve synchronized. Once you click OK, Unison will detect the files both on the desktop PC and on the laptop (it’s worth pointing out that you won’t see any sign of Unison running on the laptop, and you won’t have to do anything on the laptop—Unison runs automatically in the background).
- After a few minutes, the program window on the desktop PC will indicate the file differences between the two folders. The Path heading will show the file in question, and under the Action heading will be the “direction of travel,” indicated by an arrow—if the arrow points left, the file will be transferred to the desktop PC from the laptop. If it points right, the file will be transferred from the desktop PC to the laptop. If you don’t want to synchronize a particular file or folder, select it, and click the Skip button on the toolbar. However, assuming you’re happy with everything, click the Go button on the toolbar. The files will then be copied across. When Unison has finished (look at the status bar in the bottom left of the Unison window and the Status heading in the list of files), you can close the program window.
And that’s all there is to it. After this, you should run Unison on the desktop PC every time you want to sync the Documents folders on the two computers, such as when you get home from work. When Unison starts, just select default from the list.
Note that Unison always updates older files when synchronizing. For example, if you started a file on your desktop PC, transferred it to your laptop using Unison, and edited it while out and about, Unison would automatically overwrite the older file on the desktop PC with the updated version. This makes sense, of course. If the situation arises that the file gets updated on both machines between synchronizations, a question mark will appear alongside the file when you come to synchronize—see screenshot above—and it won’t get automatically copied across. You’ll then have to manually intervene to decide which to overwrite—the copy on the desktop PC or the copy on the laptop. Click the Right to Left toolbar button to overwrite the file on the desktop PC or the Left to Right button to overwrite the file on the laptop.
You can create additional profiles to sync other folders too—just click the Create New Profile button in Unison’s startup program window, type a name for the profile when prompted, and then double-click its entry in the list to start working through the wizard again. I find it useful to synchronize the Desktop folder on both machines because I tend to temporarily store a lot of files there. Don’t choose to sync your entire /home folder—hidden files are copied across too by Unison, and hidden files within your /home folder contain program configuration files unique to each computer. Upon synchronization there would be some almighty file clashes, and the likelihood of the login accounts on both systems getting damaged beyond repair because of mangled configuration files is high.