Kostas Vlachos

Earth Observation

Personal Website

How to organize file sharing in the COVID-19 era

Share this:

Okay, this is gonna be a quickie.

Remote work brought a lot of daily interaction between you sitting on your hot chair at home and a remote machine that acts as a server. Also, being involved in various projects you need to keep your stuff tidy. One of the issues that may restrict your productivity to some extent is modifying the same documents with different versions both at your home PC and the remote machine. In no time everything will start being very messy resulting in you being overloaded and unproductive.

So, here is a solution which is based on rsync. It’s a piece of code that you can run at the end of each day or any time you prefer. The main difference with SFTP is that with synchronization you just upload/download only the differences between local and remote host. This means that the whole procedure becomes light and relatively fast.

The assumptions are:

  • You are sitting on your personal PC
  • Remote machine has an up and running SSH service
  • Both personal and remote have rsync installed. Otherwise just follow this.

Information you will need to have beforehand is:

  • Remote username and password (or passphrase if you use public key encryption)
  • Remote public IP address
  • Remote SSH port (usually 22)
  • A local and remote directory that you need to sync

First go to the directory that contains the stuff that you want to synchronize, create a file named Makefile and open it with your favorite text editor. I will use gedit for that.

$ cd /path/to/local/folder/
$ touch Makefile
$ gedit Makefile & disown

Then paste the following lines, change the local, remote, username and remote public IP based on your case, and save/close file.

rs=rsync -azP --exclude=Makefile --delete
local=/path/to/local/folder/
remote=/path/to/remote/folder/
username=myusername

rs-send:
	$(rs) ${local} ${username}@<remote public IP>:${remote}

rs-send-dry:
	$(rs) ${local} ${username}@<remote public IP>:${remote} --dry-run
	
rs-receive:
	$(rs) ${username}@<remote public IP>:${remote} ${local}

rs-receive-dry:
	$(rs) ${username}@<remote public IP>:${remote} ${local} --dry-run

So what you have done is create four sets of commands that can be ran using the make command like the example below while being the same directory as Makefile is:

$ make rs-send-dry

Avoid data loss

The --dry-run option is used to just check what the differences between local and remote host are without applying any change. It is advised to follow the safest route first by using the rs-send-dry and rs-receive-dry commands.

Other applications

The rsync approach in syncing files can have many applications e.g., keeping backups in a network or external USB drive and so on. One useful application is to sync Thunderbird mails and filters across multiple machines. This would be applicable when mail server makes use of POP3 protocol only, instead of IMAP. In this case what you need to sync are files inside /home/user/.thunderbird/<profile name> /Mail/<pop3 server>/.

For more info on rsync use case you can check this and this.

Thank for reading and keep reading!

Tags:
Share this:

Leave a Comment

Your email address will not be published. Required fields are marked *