This Docker app runs a single time, dumping a MySQL database with mydumper and using rclone to push that data to Cloudflare R2.
You schedule the container to run at whatever interval you want backups to happen.
The container needs the environment variables related to MySQL:
MYSQL_HOST
: The host to connect to, for examplelocalhost
or127.0.0.1
.MYSQL_DATABASE
: The name of the database to dump.MYSQL_PORT
: The port to connect to, defaults to3306
MYSQL_USER
: Username for MySQLMYSQL_PASSWORD
: Password for MySQL
And these variables related to Cloudflare R2:
R2_ACCESS_KEY_ID
andR2_SECRET_ACCESS_KEY
: An S3-compatible access keyR2_ENDPOINT
: The S3 API URL for your R2 accountR2_BUCKET
: The name of the bucket to upload toR2_PATH
: A folder within the R2 bucket to upload to, defaults to"mysql-backup"
Tip
You can also deploy MySQL with these backups enabled if you don't have a database yet.
If you're running this container in Railway, you can use shared variables for all the MySQL variables (replace MySQL
in each expression with the name of your database service):
MYSQL_HOST
:${{MySQL.MYSQLHOST}}
MYSQL_DATABASE
:${{MySQL.MYSQL_DATABASE}}
MYSQL_PORT
:${{MySQL.MYSQLPORT}}
MYSQL_USER
:${{MySQL.MYSQLUSER}}
MYSQL_PASSWORD
:${{MySQL.MYSQLPASSWORD}}
Then, in settings, set restart to never and input a cron schedule to backup as often as you'd like.
- Install mydumper and rclone
- Create the same rclone config file that this container does
- Run
rclone copy remote:$R2_BUCKET/$R2_PATH ./$LOCAL_FOLDER_TO_CREATE
- Run
myloader -h $MYSQL_HOST -u $MYSQL_USER -p $MYSQL_PASSWORD -d $LOCAL_FOLDER_TO_CREATE
You can fork this repo and modify the rclone config file to work for any storage destination that rclone supports (which is pretty much everything).
Yes! mydumper
and myloader
are compatible with MariaDB as well.