Linux VPS

Back up a Linux VPS to S3-compatible storage with rclone

Install rclone, connect it to any S3-compatible bucket, back up files and database dumps, encrypt with a crypt remote, schedule with cron and restore when needed.

IntermediateLinux VPS2 min read

Snapshots on the same host are not real backups. Copying data to object storage at another provider gives you an off-site copy. This guide shows how to back up a VPS to S3 storage with rclone, encrypted and automated.

Before you start

  • A Linux VPS with root or sudo.
  • An S3-compatible bucket and an access key/secret key limited to that bucket. See object storage explained.
  • The provider's S3 endpoint URL and region.

Install rclone

sudo apt install -y rclone

Distribution packages can be old; the rclone website also offers an install script and static binaries if you need newer features.

Configure the S3 remote

rclone config
  1. Choose n (new remote), name it s3backup.
  2. Storage type: Amazon S3 Compliant Storage Providers, then pick your provider or Other.
  3. Enter the access key, secret key, region and endpoint.
  4. Accept defaults for the rest and save.

Test: rclone lsd s3backup: lists your buckets.

Create a second remote of type crypt named s3crypt pointing to s3backup:my-bucket/vps1, and set a strong password and salt. Store these somewhere safe outside the server: without them backups cannot be restored.

Back up files and databases

Dump databases first, e.g. MySQL/MariaDB:

mysqldump --all-databases --single-transaction | gzip > /var/backups/db-$(date +%F).sql.gz

Then copy data:

rclone sync /var/www s3crypt:www --backup-dir s3crypt:archive/$(date +%F) --transfers 8 --log-file /var/log/rclone.log
rclone copy /var/backups s3crypt:db --max-age 48h

sync mirrors the source; --backup-dir keeps changed or deleted files instead of losing them.

Schedule with cron

Save the commands in /usr/local/bin/backup.sh, make it executable, then add to root's crontab (crontab -e):

30 2 * * * /usr/local/bin/backup.sh

Restore

rclone copy s3crypt:www/site1 /var/www/site1

Test a restore to a temporary folder regularly, not only when disaster strikes.

Troubleshooting

  • SignatureDoesNotMatch: wrong secret key, region or endpoint.
  • AccessDenied: the key lacks permission for that bucket or action.
  • Slow uploads: raise --transfers and check the VPS bandwidth.

Frequently asked questions

Should I use sync or copy?

copy never deletes on the destination; sync mirrors deletions. Combine sync with --backup-dir or bucket versioning.

How do I clean up old backups?

Use bucket lifecycle rules, or rclone delete --min-age 30d on archive paths.

Does this work for cPanel hosting?

MdmHost hosting already includes daily JetBackup backups; see cPanel off-site backups for extra copies.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.