Automatic MySQL and MariaDB backups to cloud storage
A dated, compressed dump of your MySQL or MariaDB database every night, or as often as every 6 hours, kept in Google Drive, Amazon S3, OneDrive or any other cloud.
The do-it-yourself way: mysqldump and cron
On a server that is always on, this is the usual script. It keeps the password out of the command line, where other users of the machine could see it, by reading it from ~/.my.cnf:
#!/usr/bin/env bash
set -euo pipefail
stamp=$(date +%Y-%m-%d-%H%M%S)
file="/var/backups/shop-$stamp.sql.gz"
mysqldump --single-transaction --quick --routines --triggers shop | gzip > "$file"
rclone copy "$file" remote:db-backups/
find /var/backups -name 'shop-*.sql.gz' -mtime +14 -delete
--single-transactiongives a consistent copy of InnoDB tables without locking them; leave it out and the dump either locks every table or copies them at different moments.--routinesand--triggersmatter: stored procedures are not in a dump by default.- Without
pipefail, a failed dump still leaves a small, valid .gz file. - Nobody hears when it fails, and the copies in the cloud are never pruned.
Steps
- Sign in, open Databases and press Connect a database. Choose MySQL / MariaDB, or your hosting service by name.
- Paste the connection string (
mysql://user:password@host:3306/dbname), or fill in the server, database, username and password one by one. - If the database only answers on its own server, fill in the SSH server fields too; it is then reached through that server, and the database address is usually
localhost. - Press Schedule on its card. Choose the cloud and folder, how many backups to keep (1 to 365), and how often: every 6 hours, every 12 hours, every day, every Sunday or on the 1st of every month.
- Save. The first backup starts at once, and its progress shows in the job list.
What each backup is
- A SQL dump from
mariadb-dumpwith--single-transaction --quick --routines --triggers, in utf8mb4, gzipped as it streams: one dated file such asshop-2026-11-04-020000.sql.gz. MySQL and MariaDB servers both take it. - The oldest backups past the number you keep are removed after each good run; nothing else in the folder is touched.
- List table names to back up only those.
Encrypted backups
Give the database a backup passphrase (12 characters or more) and every backup is encrypted with AES-256 before it leaves our server; its name gains .enc. The cloud you save into then holds nothing readable. To open one on your own computer, with the OpenSSL that comes with macOS, Linux and Git for Windows:
openssl enc -d -aes-256-cbc -pbkdf2 -iter 600000 -in shop-2026-11-04-020000.sql.gz.enc -out shop-2026-11-04-020000.sql.gz
Keep the passphrase somewhere safe. Without it nobody, including us, can open the backups.
Restoring a backup
From the app: press Restore on the database's card, pick a backup, type the database's name to confirm, and start. Every table in the backup is dropped and recreated; other tables are left alone.
By hand, with the mysql or mariadb client:
gunzip -c shop-2026-11-04-020000.sql.gz | mysql -h host -u user -p shop
Amazon RDS, Aurora, PlanetScale and shared hosting
- Amazon RDS and Aurora MySQL: allow our server in the security group, or reach a private instance through a bastion host with the SSH fields.
- PlanetScale: make a password for the branch on its Connect page and paste the connection string; TLS is switched on for you.
- cPanel and other shared hosting: MySQL usually answers only on the host itself. Fill in the SSH fields with your hosting account's SSH login and use
localhostas the database address. The site's files can be backed up in the same place over SFTP or FTP.
Hosted databases usually accept connections only from addresses on an allow list. Add our server's address there, or keep the database private and use the SSH fields to reach it through a server that can.
Limits
- A backup is the data at one moment, not a continuous replica or point-in-time recovery.
- A backup stops after 2 hours, or past 20 GB compressed, unless the operator has changed those limits.
- Each backup's size counts towards your transfer allowance.
Questions
Are MyISAM tables copied consistently?
They are copied, but --single-transaction only gives a consistent snapshot of InnoDB tables. A MyISAM table being written to during the backup may not match the others. Converting it to InnoDB fixes that.
Which user should it use?
One with SELECT, SHOW VIEW, TRIGGER and EVENT on the database is enough for a backup. Restores need a user that can drop and create the tables.
Try it
Prepaid: 30 GB free, then 500 GB for ₹100 or 2,500 GB for ₹500, each valid a year. No card is asked for to start.