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 rcloneDistribution 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- Choose n (new remote), name it
s3backup. - Storage type: Amazon S3 Compliant Storage Providers, then pick your provider or Other.
- Enter the access key, secret key, region and endpoint.
- Accept defaults for the rest and save.
Test: rclone lsd s3backup: lists your buckets.
Add encryption (recommended)
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.gzThen copy data:
rclone sync /var/www s3crypt:www --backup-dir s3crypt:archive/$(date +%F) --transfers 8 --log-file /var/log/rclone.logrclone copy /var/backups s3crypt:db --max-age 48hsync 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.shRestore
rclone copy s3crypt:www/site1 /var/www/site1Test 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
--transfersand 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.
