Rclone setup for automatic backup to cloudflare R2 remote storage.
Important URLs
https://developers.cloudflare.com/r2/examples/rclone/
https://rclone.org/downloads/
https://rclone.org/install/
https://rclone.org/s3/#cloudflare-r2
Step.1 r2backup configuration.
#Install rclone on Ubuntu/Debian
sudo -v ; curl https://rclone.org/install.sh | sudo bash
#If Unzip is not installed then install (Optional)
sudo apt install zip
#Configure rclone (use name "r2backup" follow steps - leave everything blank)
rclone config
# rclone config file content
cat /root/.config/rclone/rclone.conf
#Copy below mentioned details to rclone.conf (put your cloudflare info)
[r2backup]
type = s3
provider = Cloudflare
access_key_id = **<your cloudflare r2 key ID>**
secret_access_key = **<your cloudflare r2 secret access key>**
region = auto
endpoint = https://**<your cloudflare endpoint url>**.cloudflarestorage.com
acl = private
Step.2 Verify r2backup
#List remote
rclone listremotes
#Check r2 data in tree format
rclone tree r2backup:r2backup
#Copy rclone.conf file to r2backup (for testing)
rclone copy /root/.config/rclone/rclone.conf r2backup:r2backup
Step.3 Mount r2backup Manually
#Mount r2backup to /home/backup (make sure /home/backup/ directory is empty.
#Create a new folder for rclone log file. (make sure user has write permission)
mkdir /var/log/rclone
#check fuse is installed
dpkg --get-selections | grep fuse
#Install fuse3 if not installed. (Optional)
sudo apt install fuse3
#Mount [If there is any mounting error, then Install fuse3]
rclone mount r2backup:r2backup /home/backup --allow-non-empty --allow-other --daemon --config /root/.config/rclone/rclone.conf
#verify mount (you will see r2backup:r2backup is mounted as /home/backup
df -h
#prevent r2backup mount reset after reboot (Step4)
reboot
Step.4 Automatic rclone Service
# Create a systemd service for r2backup
# Create a file rclone.service inside /etc/systemd/system and copy below code, then save (remove ###)
###
[Unit]
Description=Cloudflare R2 (rclone)
RequiresMountsFor=/home/backup
After=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/rclone mount r2backup:r2backup /home/backup \
--config /root/.config/rclone/rclone.conf \
--allow-other \
--log-level INFO \
--log-file /var/log/rclone/rclone.log
ExecStop=/bin/fusermount -uz /root/.config/rclone/rclone.conf
Restart=on-failure
RestartSec=10
KillMode=none
User=root
Group=root
[Install]
WantedBy=default.target
###
# Start and Enable the service
systemctl start rclone
systemctl enable rclone
#verify rclone service is working
systemctl status rclone