Sync Your Files with rclone
Sync your files with rclone to S3 storage or an SFTP server: client-side encryption, archives, systemd scheduling and a restore test.
On this page
Your values
Enter them once and the commands in this guide update.
This guide explains how to use rclone to send the files of your VPS or dedicated server to S3-compatible storage or another service, such as an SFTP server. Your data will be encrypted before it leaves, the sync will be scheduled, and you will check that you know how to get it back.
Prerequisites
- A server running Debian 12 or 13, or Ubuntu 22.04 or 24.04, with
sudoaccess - An S3 bucket with an access key and a secret key, or an SFTP server
- A system clock set to the correct time: see our guide Configure NTP
- A place off the server to keep the rclone configuration and the passwords
No inbound port needs to be opened. The server must be able to connect out to port 443 for S3, or to the remote server's SSH port for SFTP.
Install rclone
The project advises against distribution packages, which are often outdated. Install the official package. At the time of writing, the current version is 1.76.0: see the download page and adjust RCLONE_VERSION if needed.
RCLONE_VERSION="v1.76.0"
ARCH="$(dpkg --print-architecture)"
FILE="rclone-${RCLONE_VERSION}-linux-${ARCH}.deb"
cd /tmp
curl -fsSLO "https://downloads.rclone.org/${RCLONE_VERSION}/${FILE}"
curl -fsSLO "https://downloads.rclone.org/${RCLONE_VERSION}/SHA256SUMS"
sha256sum --check --ignore-missing SHA256SUMS
sudo apt install -y "./${FILE}"
rclone versionThe verification must show OK for the package. A warning about improperly formatted lines is normal, because the file also contains its signature.
Configure S3 storage
The examples use HostMyServers Object Storage, which is S3-compatible and whose endpoint published on that page is https://s3.lyn.io.hostmyservers.net. The bucket is called mes-sauvegardes: adapt this name.
-
Create the configuration file, readable by
rootonly:Terminalsudo install -d -m 700 /root/.config /root/.config/rclone sudo install -m 600 /dev/null /root/.config/rclone/rclone.conf sudo nano /root/.config/rclone/rclone.conf -
Add this block:
Configuration[hms-s3] type = s3 provider = Other access_key_id = YOUR_ACCESS_KEY secret_access_key = YOUR_SECRET_KEY endpoint = https://s3.lyn.io.hostmyservers.net acl = privateFor another S3-compatible provider, change
endpointand addregion = YOUR_REGIONif it requires one. -
Test access and create the bucket if it does not exist yet:
Terminalsudo rclone lsd hms-s3: sudo rclone mkdir hms-s3:mes-sauvegardes
Add encryption
The crypt type encrypts the content as well as file and folder names before upload. It works as a layer on top of the storage.
-
Generate two secrets and create the encrypted storage
hms-crypt:TerminalCRYPT_PASS="$(openssl rand -hex 32)" CRYPT_SALT="$(openssl rand -hex 32)" sudo rclone config create hms-crypt crypt remote=hms-s3:mes-sauvegardes/crypt filename_encryption=standard directory_name_encryption=true password="$CRYPT_PASS" password2="$CRYPT_SALT" --obscure printf 'password: %s\npassword2: %s\n' "$CRYPT_PASS" "$CRYPT_SALT" unset CRYPT_PASS CRYPT_SALT -
Copy the two displayed values to your password manager, then also back up the
rclone.conffile off the server:Terminalsudo cat /root/.config/rclone/rclone.conf -
Check that names are really encrypted remotely:
Terminalecho "rclone test" | sudo tee /tmp/rclone-test.txt > /dev/null sudo rclone copy /tmp/rclone-test.txt hms-crypt:test sudo rclone ls hms-crypt:test sudo rclone ls hms-s3:mes-sauvegardes/crypt sudo rclone purge hms-crypt:testThe first listing shows
rclone-test.txt, the second an unreadable name.
With standard encryption, limit file names to about 143 characters to avoid any problem.
Choose the right command
| Command | Effect | Risk |
|---|---|---|
rclone copy |
Copies new or modified files, without deleting anything | Low |
rclone sync |
Makes the destination identical to the source, deletions included | High |
rclone move |
Copies then deletes from the source | High |
rclone check |
Compares source and destination | None |
rclone cryptcheck |
Compares local files with encrypted storage | None |
Run a first sync
The examples sync /srv/data. Replace this path with your folder.
-
Create the exclusion list:
Terminalsudo nano /etc/rclone-sync.filterText- *.tmp - .cache/** - node_modules/** -
Always simulate before syncing:
Terminalsudo rclone sync /srv/data hms-crypt:current --filter-from /etc/rclone-sync.filter --dry-run --verbose -
If the list looks right, start the upload:
Terminalsudo rclone sync /srv/data hms-crypt:current --filter-from /etc/rclone-sync.filter --progress -
Check the result:
Terminalsudo rclone cryptcheck /srv/data hms-crypt:current --one-way --filter-from /etc/rclone-sync.filter
Test the restore
Do this test now, then regularly. A remote copy is only useful if you know how to read it back and decrypt it.
-
Restore everything into a temporary folder and compare:
Terminalsudo rm -rf /var/tmp/rclone-restore sudo rclone copy hms-crypt:current /var/tmp/rclone-restore --progress sudo diff -r /srv/data /var/tmp/rclone-restore | head -n 20Only files that are excluded or were modified since the sync should appear.
-
Also restore a single file, adjusting its path:
Terminalsudo rclone copyto hms-crypt:current/dossier/fichier.txt /var/tmp/fichier-restaure.txt -
Test recovery on another machine: install rclone, put
rclone.confback from your external copy into/root/.config/rclone/, then run the samerclone copycommand. This test proves that your copy of the configuration is complete. -
Then delete the test files:
Terminalsudo rm -rf /var/tmp/rclone-restore /var/tmp/fichier-restaure.txt
Schedule the sync
The following script moves each replaced or deleted file into a dated archive folder, and keeps the last 30.
-
Create the script:
Terminalsudo nano /usr/local/sbin/rclone-sync.shTerminal#!/bin/bash set -euo pipefail SOURCE="/srv/data" REMOTE="hms-crypt:" KEEP_ARCHIVES=30 STAMP="$(date +%F_%H%M%S)" rclone sync "$SOURCE" "${REMOTE}current" \ --backup-dir "${REMOTE}archive/$STAMP" \ --filter-from /etc/rclone-sync.filter \ --max-delete 1000 \ --fast-list \ --log-level INFO \ --stats 5m \ --stats-one-line { rclone lsf --dirs-only "${REMOTE}archive" 2>/dev/null || true; } | sort | head -n -"$KEEP_ARCHIVES" | while IFS= read -r dir; do rclone purge "${REMOTE}archive/${dir%/}" done--max-delete 1000aborts the operation if more than 1,000 files would be removed. This limit protects your data if the source folder is empty by mistake, for example when a disk is not mounted. Adjust it to your volume. -
Create the service:
Terminalsudo chmod 700 /usr/local/sbin/rclone-sync.sh sudo nano /etc/systemd/system/rclone-sync.serviceConfiguration[Unit] Description=rclone sync Wants=network-online.target After=network-online.target [Service] Type=oneshot Environment=HOME=/root Nice=10 IOSchedulingClass=idle ExecStart=/usr/local/sbin/rclone-sync.sh -
Create the timer:
Terminalsudo nano /etc/systemd/system/rclone-sync.timerConfiguration[Unit] Description=Daily rclone sync [Timer] OnCalendar=*-*-* 04:15:00 RandomizedDelaySec=20min Persistent=true [Install] WantedBy=timers.target -
Enable it and run a first pass:
Terminalsudo systemctl daemon-reload sudo systemctl enable --now rclone-sync.timer sudo systemctl start rclone-sync.service sudo journalctl -u rclone-sync.service -n 30 --no-pager
To recover an older version, list the archives then copy the file you want:
sudo rclone lsf hms-crypt:archive
sudo rclone copyto hms-crypt:archive/2026-11-18_041500/dossier/fichier.txt /var/tmp/ancienne-version.txtThe versioning advertised on the HMS offer page can complement this mechanism. The versions kept then count toward the billed volume.
Use another service: SFTP example
rclone supports many services, listed in its documentation. Here is how to target another server over SFTP, in this case backup.your-domain.com.
-
Create a dedicated key, install it on the remote server and record its fingerprint:
Terminalsudo install -d -m 700 /root/.ssh sudo ssh-keygen -t ed25519 -N '' -C 'rclone' -f /root/.ssh/rclone_sftp sudo ssh-copy-id -i /root/.ssh/rclone_sftp.pub YOUR_USER@backup.your-domain.com sudo ssh -i /root/.ssh/rclone_sftp YOUR_USER@backup.your-domain.com trueOn the first connection, compare the displayed fingerprint with the remote server's before accepting.
-
Add this block to
/root/.config/rclone/rclone.conf:Configuration[backup-sftp] type = sftp host = backup.your-domain.com user = YOUR_USER port = 22 key_file = /root/.ssh/rclone_sftp known_hosts_file = /root/.ssh/known_hosts -
Test access:
Terminalsudo rclone mkdir backup-sftp:rclone sudo rclone lsd backup-sftp: -
To encrypt this data too, create a second
cryptstorage:TerminalCRYPT_PASS="$(openssl rand -hex 32)" CRYPT_SALT="$(openssl rand -hex 32)" sudo rclone config create sftp-crypt crypt remote=backup-sftp:rclone/crypt password="$CRYPT_PASS" password2="$CRYPT_SALT" --obscure printf 'password: %s\npassword2: %s\n' "$CRYPT_PASS" "$CRYPT_SALT" unset CRYPT_PASS CRYPT_SALTKeep these values off the server, then set
REMOTE="sftp-crypt:"in the script to use this destination.
Update rclone
rclone selfupdate --check
sudo rclone selfupdate --package deb
rclone versionAfter an update, run the sync by hand and check its log.
Troubleshooting
didn't find section in config file
The name before the colon does not match any block in the configuration, or rclone is reading another file. With sudo, check:
sudo rclone config file
sudo rclone listremotesSignatureDoesNotMatch, InvalidAccessKeyId or AccessDenied
Check both keys and the endpoint shown for your service. If the error mentions a region, add region with the value provided by your storage provider, or contact support from your customer area.
RequestTimeTooSkewed
The server clock is off. Check it with timedatectl, then follow our guide Configure NTP.
NoSuchBucket or directory not found
The bucket or the path does not exist. Check its name with sudo rclone lsd hms-s3:. For a source folder, check that it really exists on the server.
failed to authenticate decrypted block - bad password?
The crypt password does not match the data, or the remote file is damaged. Restore rclone.conf from your external copy, without recreating the encrypted storage with new secrets.
--max-delete threshold reached
The number of deletions exceeds your limit, and the operation stops. First check that the source is complete, then verify with --dry-run. Only raise the limit if these deletions are really intended.
file name too long
The encrypted name exceeds the storage limit. Shorten the file names concerned, aiming for 143 characters at most.
The service fails without a clear message
Increase the level of detail by running the script by hand with --log-level DEBUG added to the rclone sync command, then check:
sudo systemctl status rclone-sync.service --no-pager
sudo journalctl -u rclone-sync.service -n 100 --no-pager