jonny
June 9th, 2005, 09:51 AM
Do you need to keep a laptop synchronised with a server or a mounted filesystem, such as a removable storage device? If so, read on.
At work, I use ubuntu on a laptop for most tasks. I'm not always connected to the office network, so I keep all my documents on the local hard drive. But keeping important files on a laptop is a bad idea – backups are difficult, and my colleagues can't easily share my documents. So I also keep a copy of my data on an office server.
Sometimes, though, I need to work collaboratively on a document. That means that the master copy is on the server – but I also like to keep a copy on my laptop for when I'm working offline. This creates a problem for me: which files do I need to copy to or from the server? Sometimes I get muddled up, and I've lost work by overwriting new documents with older ones. So, in a moment of exasperation, I wrote a brief script to help me.
This script synchronises my laptop with the server. If the local file is newer, it copies it to the server. If the remote file is newer, it copies it to my laptop. If both files are the same, it ignores them. I've been using the script for a few months and it works flawlessly for me, so I thought I'd share it.
First, you need to decide which directories you want to synchronise. I keep my local files in a directory called /home/jonny/Briefcase, and I mount the remote files in a directory called /home/jonny/RemoteBriefcase (visit www.ubuntuguide.org for advice if you don't know how to mount a network drive).
Next, you need to create a script. Open Text Editor and enter this code#!/bin/bash
cp -rpuv ~/RemoteBriefcase/* ~/Briefcase/
cp -rpuv ~/Briefcase/* ~/RemoteBriefcaseSave it somewhere, and create a shortcut to it on your Gnome panel. Now you have one-click synchronisation.
This script comes with a two provisos.
- First, be aware that makes no attempt to warn you if both the server and the local version have been edited since you last synchronised.
- Second, some remote filesystems won't let you backdate a file's last edited date. If you edit a file locally and then synchronise, the server will timestamp it when you synchronise. That means that the file will then be copied back to your laptop next time you synchronise. This is harmless, but could cause concern if you aren't expecting it to happen.
At work, I use ubuntu on a laptop for most tasks. I'm not always connected to the office network, so I keep all my documents on the local hard drive. But keeping important files on a laptop is a bad idea – backups are difficult, and my colleagues can't easily share my documents. So I also keep a copy of my data on an office server.
Sometimes, though, I need to work collaboratively on a document. That means that the master copy is on the server – but I also like to keep a copy on my laptop for when I'm working offline. This creates a problem for me: which files do I need to copy to or from the server? Sometimes I get muddled up, and I've lost work by overwriting new documents with older ones. So, in a moment of exasperation, I wrote a brief script to help me.
This script synchronises my laptop with the server. If the local file is newer, it copies it to the server. If the remote file is newer, it copies it to my laptop. If both files are the same, it ignores them. I've been using the script for a few months and it works flawlessly for me, so I thought I'd share it.
First, you need to decide which directories you want to synchronise. I keep my local files in a directory called /home/jonny/Briefcase, and I mount the remote files in a directory called /home/jonny/RemoteBriefcase (visit www.ubuntuguide.org for advice if you don't know how to mount a network drive).
Next, you need to create a script. Open Text Editor and enter this code#!/bin/bash
cp -rpuv ~/RemoteBriefcase/* ~/Briefcase/
cp -rpuv ~/Briefcase/* ~/RemoteBriefcaseSave it somewhere, and create a shortcut to it on your Gnome panel. Now you have one-click synchronisation.
This script comes with a two provisos.
- First, be aware that makes no attempt to warn you if both the server and the local version have been edited since you last synchronised.
- Second, some remote filesystems won't let you backdate a file's last edited date. If you edit a file locally and then synchronise, the server will timestamp it when you synchronise. That means that the file will then be copied back to your laptop next time you synchronise. This is harmless, but could cause concern if you aren't expecting it to happen.