rss logo

How to Synchronize Files between Computers and Cloud Storage with Rclone

Rclone Logo

I was looking for a way to automatically synchronize a KeePass file between two computers that aren't on the same network and don't have access to a shared drive. After some personal research, I discovered the wonderful Rclone tool, which met all my requirements. It's open source, free (you can support the project here: https://rclone.org/sponsor/), and it supports a wide range of cloud storage services, including Proton Drive.

  • Here's what we're going to do:
    • Synchronize a KeePass file between two Windows workstations to take account of changes made by two users: user01 and user02.
    • Use Proton Drive cloud storage.
    • Enable Rclone's Bi-Sync mode, which allow the KeePass file to be modified on both computers.

⚠️Note: Please bear in mind that the bi-sync option in Rclone is still under development. It is therefore essential to create regular file backups to avoid any potential data loss.⚠️

Diagram showing Rclone synchronization of a KeePass file (pwd.kdbx) between Proton Drive and two computers (PC01 and PC02) using cloud storage.

Create a Proton Account

Screenshot of Proton account creation page with fields for username, password, and a 'Create account' button.
  • From the main menu, click on the Drive to activate the Cloud Storage service:
Screenshot showing Proton Mail interface with an arrow pointing to the Drive activation icon in the application menu.

Rclone

Configuring Rclone with Proton Drive on PC01 and PC02

Screenshot of the Rclone website with a highlighted link for downloading the software.
  • Choose the appropriate download link according to your architecture:
Screenshot of the Rclone download page highlighting the Windows 64-bit download option with an arrow.
  • Extract the contents of the zip archive and rename the extracted folder to rclone:
Screenshot showing the extraction of the Rclone ZIP file on Windows and the resulting folder contents.
  • Open a terminal from the extracted folder and run the ".\rclone.exe config" command:
Screenshot showing the option to open Windows Terminal in the Rclone folder and execute the rclone.exe config command in PowerShell.
  • Follow the setup instructions and answer the questions asked as shown below:
PS C:\Users\user\Downloads\rclone> .\rclone.exe config 2023/10/07 14:46:36 NOTICE: Config file "C:\\Users\\user\\AppData\\Roaming\\rclone\\rclone.conf" not found - using defaults No remotes found, make a new one? n) New remote s) Set configuration password q) Quit config n/s/q> n Enter name for new remote. name> proton Option Storage. Type of storage to configure. Choose a number from below, or type in your own value. 1 / 1Fichier \ (fichier) 2 / Akamai NetStorage \ (netstorage) 3 / Alias for an existing remote \ (alias) […] 37 / Proton Drive \ (protondrive) 38 / Put.io \ (putio) 39 / QingCloud Object Storage \ (qingstor) 40 / Quatrix by Maytech \ (quatrix) 41 / SMB / CIFS \ (smb) […] Storage> 37 Option username. The username of your proton account Enter a value. username> YOUREMAILADDRESS@proton.me Option password. The password of your proton account. Choose an alternative below. y) Yes, type in my own password g) Generate random password y/g> y Enter the password: password: ******** Confirm the password: password: ******** Option 2fa. The 2FA code The value can also be provided with --protondrive-2fa=000000 The 2FA code of your proton drive account if the account is set up with two-factor authentication Enter a value. Press Enter to leave empty. 2fa> Edit advanced config? y) Yes n) No (default) y/n> n Configuration complete. Options: - type: protondrive - username: YOUREMAILADDRESS@proton.me - password: *** ENCRYPTED *** Keep this "proton" remote? y) Yes this is OK (default) e) Edit this remote d) Delete this remote y/e/d> y Current remotes: Name Type ==== ==== proton protondrive e) Edit existing remote n) New remote d) Delete remote r) Rename remote c) Copy remote s) Set configuration password q) Quit config e/n/d/r/c/s/q> q
  • Check that the connection to Proton Drive is working:
PS C:\Users\user\Downloads\rclone> .\rclone.exe ls proton:
  • If the following error message appears, make sure you have previously opened the Proton Drive application from the web interface, as explained above:
2023/10/07 15:44:12.806871 ERROR RESTY 401 GET https://mail.proton.me/api/core/v4/users: Invalid access token (Code=401, Status=401), Attempt 1 2023/10/07 15:44:12.945153 ERROR RESTY 422 POST https://mail.proton.me/api/auth/v4/refresh: Invalid refresh token (Code=10013, Status=422), Attempt 1 2023/10/07 15:44:16 mainShare &proton.Share{ShareMetadata:proton.ShareMetadata{ShareID:"", LinkID:"", VolumeID:"", Type:0, State:0, CreationTime:0, ModifyTime:0, Creator:"", Flags:0, Locked:false, VolumeSoftDeleted:false}, AddressID:"", AddressKeyID:"", Key:"", Passphrase:"", PassphraseSignature:""} 2023/10/07 15:44:16 shares []proton.ShareMetadata{} 2023/10/07 15:44:16 Failed to create file system for "proton:": couldn't initialize a new proton drive instance: the main share assumption has failed

Using Rclone

Once Cloud Storage is configured, let's see what we can do with this tool.

  • Display configured cloud:
PS C:\Users\user\Downloads\rclone> .\rclone.exe listremotes proton:
  • Create an empty TEST.txt file in Proton Drive:
PS C:\Users\user\Downloads\rclone> .\rclone.exe touch proton:TEST.txt Screenshot of Proton Drive interface showing a file named TEST.txt in the My files section.
  • Synchronize the Cloud Drive with the local folder C:\Users\user\Desktop\PROTON\:
PS C:\Users\user\Downloads\rclone> .\rclone.exe sync proton: C:\Users\user\Desktop\PROTON\ Screenshot of a Windows folder named PROTON showing a synchronized file named TEST.txt.
  • List Cloud Drive files:
PS C:\Users\user\Downloads\rclone> .\rclone.exe ls proton: 0 TEST.txt
  • Check version and update Rclone to the latest available version, if necessary:
PS C:\Users\user\Downloads\rclone> .\rclone.exe selfupdate 2023/10/07 16:39:33 NOTICE: rclone is up to date
  • Show all available Rclone options:
PS C:\Users\user\Downloads\rclone> .\rclone.exe Usage: rclone [flags] rclone [command] Available Commands: about Get quota information from the remote. authorize Remote authorization. backend Run a backend-specific command. bisync Perform bidirectional synchronization between two paths. cat Concatenates any files and sends them to stdout. check Checks the files in the source and destination match. checksum Checks the files in the source against a SUM file. cleanup Clean up the remote if possible. completion Output completion script for a given shell. config Enter an interactive configuration session. copy Copy files from source to dest, skipping identical files. copyto Copy files from source to dest, skipping identical files. copyurl Copy url content to dest. cryptcheck Cryptcheck checks the integrity of an encrypted remote. cryptdecode Cryptdecode returns unencrypted file names. dedupe Interactively find duplicate filenames and delete/rename them. delete Remove the files in path. deletefile Remove a single file from remote. gendocs Output markdown docs for rclone to the directory supplied. hashsum Produces a hashsum file for all the objects in the path. help Show help for rclone commands, flags and backends. link Generate public link to file/folder. listremotes List all the remotes in the config file and defined in environment variables. ls List the objects in the path with size and path. lsd List all directories/containers/buckets in the path. lsf List directories and objects in remote:path formatted for parsing. lsjson List directories and objects in the path in JSON format. lsl List the objects in path with modification time, size and path. md5sum Produces an md5sum file for all the objects in the path. mkdir Make the path if it doesn't already exist. mount Mount the remote as file system on a mountpoint. move Move files from source to dest. moveto Move file or directory from source to dest. ncdu Explore a remote with a text based user interface. obscure Obscure password for use in the rclone config file. purge Remove the path and all of its contents. rc Run a command against a running rclone. rcat Copies standard input to file on remote. rcd Run rclone listening to remote control commands only. rmdir Remove the empty directory at path. rmdirs Remove empty directories under the path. selfupdate Update the rclone binary. serve Serve a remote over a protocol. settier Changes storage class/tier of objects in remote. sha1sum Produces an sha1sum file for all the objects in the path. size Prints the total size and number of objects in remote:path. sync Make source and dest identical, modifying destination only. test Run a test command touch Create new file or change file modification time. tree List the contents of the remote in a tree like fashion. version Show the version number. Use "rclone [command] --help" for more information about a command. Use "rclone help flags" for to see the global flags. Use "rclone help backends" for a list of supported services.

Setting up Bisynchronization

Now that we've briefly explored how to use Rclone, let's get back to our main objective: synchronizing a KeePass file between two hosts.

PC01

  • Create a directory C:\RCLONE\:
PS C:\Users\user\Downloads\rclone> mkdir C:\RCLONE
  • Send file C:\RCLONE\pwd.kdbx to Proton Drive:
PS C:\Users\user\Downloads\rclone> .\rclone.exe sync C:\RCLONE\pwd.kdbx proton: Diagram showing file synchronization from PC01 to Proton Drive using Rclone with a secure file labeled pwd.kdbx.
  • Activate bisync between C:\RCLONE\ and Proton Drive:
PS C:\Users\user\Downloads\rclone> .\rclone.exe bisync C:\RCLONE\ proton: --resync Diagram illustrating bidirectional synchronization of the pwd.kdbx file between PC01 and Proton Drive using Rclone.
  • Perform a bidirectional synchronization between C:\RCLONE\ and Proton Drive:
PS C:\Users\user\Downloads\rclone> .\rclone.exe bisync C:\RCLONE\ proton: --force

PC02

  • Create a directory C:\RCLONE\:
PS C:\Users\user\Downloads\rclone> mkdir C:\RCLONE
  • Retrieve the file pwd.kdbx from Proton Drive to C:\RCLONE\:
PS C:\Users\user\Downloads\rclone> .\rclone.exe sync proton: C:\RCLONE\ Diagram showing file synchronization from Proton Drive to PC02 using Rclone with a secure file labeled pwd.kdbx.
  • Enable bisync between C:\RCLONE\ and Proton Drive:
PS C:\Users\user\Downloads\rclone> .\rclone.exe bisync C:\RCLONE\ proton: --resync Diagram showing Rclone synchronization of a KeePass file (pwd.kdbx) between Proton Drive and two computers (PC01 and PC02) using cloud storage.
  • Perform bidirectional synchronization between C:\RCLONE\ and Proton Drive:
PS C:\Users\user\Downloads\rclone> .\rclone.exe bisync C:\RCLONE\ proton: --force

Automating Bisynchronization with the Windows Task Scheduler

The architecture is now configured and functional, but we need to manually run the .\rclone.exe bisync C:\RCLONE\ proton: --force command on each computer each time the pwd.kdbx file is modified. To automate this process, we'll use a batch script which will be run by the Windows Task Scheduler.

Batch Script

Create a C:\rclone.bat script.

@echo off REM VARIABLES set SOURCE=C:\RCLONE set DESTINATION=proton: set DOWNLOADS=C:\Users\USERNAME\Downloads REM UPDATE RCLONE TO LATEST RELEASE %DOWNLOADS%"\rclone\rclone.exe" selfupdate REM FORCE BISYNC %DOWNLOADS%"\rclone\rclone.exe" bisync %SOURCE% %DESTINATION% --force

Windows Task Scheduler

  • Open the Windows Task Scheduler:
Screenshot of the Windows Run dialog box with the command tasksched.msc entered to open Task Scheduler.
  • Create a new task:
Screenshot of Windows Task Scheduler with the Create Task option highlighted in the menu.
  • Give the task a name and configure it as shown below:
Screenshot of Task Scheduler's Create Task window showing general settings with the task name KeePass_Sync and options to run whether the user is logged on or not.
  • In the Triggers tab, click on New… and set the task to run every 5 minutes (adjust this value as required):
Screenshot of Task Scheduler's trigger settings with options to set a task to run one time, repeat every 5 minutes indefinitely, and confirmation with OK.
  • In the Actions tab, click on New… and set the previously created batch script, adding C:\Users\user\Downloads\rclone\ to the Start in option:
Screenshot of Task Scheduler's action settings, showing a batch script rclone.bat set to start in the Downloads folder.
  • Finally, in the Conditions tab, specify that the task should only start if a network connection is available:
Screenshot of Task Scheduler conditions tab with the option to start the task only if a network connection is available set to Any connection.