How to backup a YunoHost VPS to S3 compatible bucket.
So, i wrote a blog post about automatically creating and storing YunoHost backups, on a remote VPS. Read it here
My friend needed a similar solution, but needed to sync the backup files to an S3 bucket.
For this solution we will modify this guide, provided by Contabo
This guide is actually awesome, and you should read it. We will be changing some things, since we are backing up from the YunoHost core, and not the entire filesystem.
First of all, we need to set up automatic backups of your YunoHost VPS:
sudo crontab -e
Add this line, save and exit:
11 0 * * * yunohost backup create
This will create a full backup each night. If you want a different solution, please see the official YunoHost documentation
To install rclone enter:
sudo apt update && sudo apt install rclone -y
To configure Rclone with your S3 credentials please see this guide
To automate rclone we will make a script.
Either choose to copy the backups to the S3 bucket each night, keeping the files on your YunoHost VPS:
/usr/bin/rclone sync -P --update --verbose --transfers 30 --log-file=/var/log/upload.log "/home/yunohost.backup/archives/" "eu2:backup/"
Or move the files to S3, deleting them from the YunoHost VPS after the upload:
/usr/bin/rclone move -P --update --verbose --transfers 30 --log-file=/var/log/upload.log "/home/yunohost.backup/archives/" "eu2:backup/"
Make a file with one of the above commands, save it as rclone.sh and voila you have a script.
Make the script executable by entering:
sudo chmod +x /path/to/rclone.sh
To make the script run every night we need to create a cronjob:
sudo crontab -e
Paste in this line at the bottom, save and exit:
0 2 * * * /path/to/rclone.sh
If you chose to copy rather than to move your backup files to your S3 bucket, you might end up filling your precious drives rather quickly.
Consider using move if you do not want to keep any backups on your YunoHost VPS.
If you want to keep some backups on the VPS, consider using copy and follow the steps, in the last part of my previous post, to delete backups older than 'x' days