Ubuntu / Linux news and application reviews.

We talked about remote Bittorrent clients a couple of times (using rtorrent and wtorrent and transmission-daemon with a remote GUI) and now I am going to tell you how to incrementally sync (every 5 minutes in my example) the remote downloaded torrents with your computer.

Why would you need this? Let me tell you for what I'm using it: on my work computer, most of the ports are blocked, meaning I cannot use a Bittorrent client. I can, however, use a remote Bittorrent client, and then I use the steps described in this article to synchronize the remote Bittorrent download folder with a local folder. Using this, I can basically use a Bittorrent client on my work computer, even though it's a remote one - the files end up being downloaded on my local computer.

Obviously, you can use this for other purposes too, like remote back-up, simple folder synschronization and so on. In this article, I am going to explain syncing the remote folder with a folder on your local computer, but the other way around is possible, just use the same instructions, but replace "local" with "remote" and the other way around, in the steps provided below.

For this, we are going to use rsync, an open source utility that provides fast incremental file transfer. So make sure rsync in installed on both computers. To install rsync in Ubuntu, simply:
sudo apt-get install rsync


Let's get started!

1. Generating a shh key pair so you don't need a password for ssh (because you won't be able to use cron, etc, if a password is asked every time you try to sync your files).

ssh-keygen -t rsa


Then press Enter when prompted where to save the key and press Enter again twice when asked for a passphrase - don't enter any passphrase!

2. Copy the key to the remote computer

ssh-copy-id -i /path/to/.ssh/id_rsa.pub username@IP


Replace /path/to with the path to the newly created id_rsa.pub file (the path should be displayed in the terminal after completing step 1). In my case, the path is /home/andrei/.ssh/id_rsa.pub

Also replace username@IP.com with your remote computer username username and the remote computer IP.

You should now be able to login to username@IP without a password, so try it:
ssh username@IP


3. Creating the cron job

On your local computer, open a terminal and enter this:
crontab -e


And enter your command like so:
*/5 * * * *  rsync -r username@IP:/path/to/remote/folder/ /path/to/local/folder

Obviously, replace the variables in the command above with what you need. If you don't know how to use cron, see this graphical cron explanation.

"*/5 * * * *" means running the command every 5 minutes. You can change this to your whatever you want or simply run this command manually if you wish. Also, you can manually enter this command if you wish to manually synchronize the folders.

"-r" - means recursive - so all the contents of folder/, including subfolders will be synchronized with your local folder/.

That's it. Now save the changes and exit. To see if rsync works correctly, you can enter the command manually:
sync -r username@IP:/path/to/remote/folder/ /path/to/local/folder