DEV Community

Cover image for Backup S3 buckets using rclone
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

Backup S3 buckets using rclone

Backing up our files is a crucial task that we don't consider until it's too late. Using rclone, we can make a backup of all our data stored in S3 buckets.

Installing rclone

First, we need to install rclone. We'll be using Ubuntu Server, but you can use any distribution supported.

curl https://rclone.org/install.sh | sudo bash
Enter fullscreen mode Exit fullscreen mode

Once we've installed it, we can verify it.

rclone version
Enter fullscreen mode Exit fullscreen mode
rclone v1.72.1
 - os/version: ubuntu 24.04 (64 bit)
 - os/kernel: 6.8.0-90-generic (x86_64)
 - os/type: linux
 - os/arch: amd64
 - go/version: go1.25.5
 - go/linking: static
 - go/tags: none
Enter fullscreen mode Exit fullscreen mode

Configure the remote

To connect to our S3 storage, we must create a rclone remote.

rclone config
Enter fullscreen mode Exit fullscreen mode

This command will prompt us to answer a few questions to configure it correctly.

Some options may differ from this example, so take your time reviewing the options offered to select the one that best suits your case.

n) New remote
name> s3-storage

Storage> s3
provider> Other
env_auth> false
access_key_id> ACCESS_ID_KEY
secret_access_key> ACCESS_SECRET_KEY
region> REGION
endpoint> http://s3.example.com
location_constraint>
acl> private
y/e/d> y
e/n/d/r/c/s/q> q
Enter fullscreen mode Exit fullscreen mode

Test the remote

Once we've configured the remote, we need to test it. Running the following command should list all buckets available:

rclone lsd s3-storage:
Enter fullscreen mode Exit fullscreen mode
-1 2026-01-29 21:09:35        -1 bucket-1
-1 2026-01-29 20:05:31        -1 bucket-2
Enter fullscreen mode Exit fullscreen mode

Configuring the backup

To back up the S3 storage, we'll create a backup script.

vi /usr/local/bin/s3-backup.sh
Enter fullscreen mode Exit fullscreen mode
#!/bin/bash
set -e

LOG="/var/log/rclone-backup.log"
DEST="/backup"

rclone sync garage: "$DEST" \
  --checksum \
  --fast-list \
  --s3-no-check-bucket \
  --transfers=8 \
  --checkers=16 \
  --log-file="$LOG" \
  --log-level INFO
Enter fullscreen mode Exit fullscreen mode

This script will back up all S3 buckets to the /backup folder.

Next, we make the script executable.

chmod +x /usr/local/bin/s3-backup.sh
Enter fullscreen mode Exit fullscreen mode

And run it to create the first backup.

s3-backup.sh
Enter fullscreen mode Exit fullscreen mode

Set up a cron job

To run the backup periodically, we must create a cron job.

crontab -e
Enter fullscreen mode Exit fullscreen mode
# Backup Garage S3 to QNAP daily at 02:00.
0 2 * * * /usr/local/bin/s3-backup.sh
Enter fullscreen mode Exit fullscreen mode

This cron job will run the backup script every day at 02:00.

Top comments (0)