Backup and Restore MySQL and MariaDB Databases and Tables
Table of Contents
Database backups
Streaming full MySQL and MariaDB database backups can be accomplished quite easily by running the following command:
mysqldump -A | elastio stream backup --stream-name <stream-name>
Table-level backups
For now, table-level backups can only be accomplished by dumping each table into a separate backup. To achieve this, get a list of the database tables and loop through them as follows:
$ TABLES=$(mysql -e "SHOW TABLES;" <database> | xargs)
$ for table in ${TABLES}; do
> echo "Backing up database.${table} to elastio..."
> mysqldump <database> ${table} | elastio stream backup --stream-backup mysql_DBNAME_${table} --tag <database>:${table}
> done
Restore a table from a backup
Run the following command to restore a sample table ( addresses
) from a sample database ( customers
):
Note: This will work in conjunction with the naming used above.
elastio rp list | grep "customers_addresses"
elastio stream restore --rp <elastio-rp-id> > addresses.sql
The other option is to restore the tables directly to the database as follows:
elastio stream restore --rp <elastio-rp-id> | mysql