Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Forked from yankcrime/backup-and-restore.rst
Created December 31, 2022 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/9ec8d52b6cb25d6b6005885460b55a74 to your computer and use it in GitHub Desktop.
Save gilangvperdana/9ec8d52b6cb25d6b6005885460b55a74 to your computer and use it in GitHub Desktop.
Kolla-Ansible Backup and Restore

Backup and Restore of MariaDB

Kolla can facilitate either full or incremental backups of data hosted in MariaDB. It achieves this using Percona's Xtrabackup, a tool designed with hot backups in mind - an approach which means that consistent backups can be taken without any downtime for your cloud.

Note

By default, backups will be performed on the first node in your Galera cluster or on the MariaDB node itself if you just have the one. Backup files are saved to a dedicated Docker volume - mariadb_backup - and it's the contents of this that you should target for transferring backups elsewhere.

Backup Procedure

To perform a full backup, run the following command:

kolla-ansible mariadb_backup

Or to perform an incremental backup:

kolla-ansible mariadb_backup -e mariadb_backup_type=incremental

Kolla doesn't currently manage the scheduling of these backups, so you'll need to configure an appropriate scheduler (i.e cron) to run these commands on your behalf should you require regular snapshots of your data. A suggested schedule would be:

  • Daily full, retained for two weeks
  • Hourly incremental, retained for one day

Restoring backups

Restoring from a backup is a manual procedure, although the Kolla xtrabackup image contains the tooling necessary to stage the various files.

For a full backup, start a new container using the XtraBackup image with the appropriate options on the master database node:

docker run -it --volumes-from mariadb --name dbrestore \
   -v mariadb_backup:/backup kolla/centos-binary-xtrabackup:queens \
   /bin/bash
cd /backup
mkdir full
cat mysqlbackup-04-10-2018.xbc.xbs | xbstream -x -C ./full/
innobackupex --decompress .
rm -f /backup/full/*.qp
innobackupex --apply-log /backup/full

Then stop the MariaDB instance, delete the old data files (or move them elsewhere), and copy the backup into place:

docker stop mariadb
rm -rf /var/lib/mysql/* /var/lib/mysql/.*
innobackupex --copy-back /backup/full

Then you can restart MariaDB with the restored data in place:

docker start mariadb
docker logs mariadb
81004 15:48:27 mysqld_safe WSREP: Running position recovery with --log_error='/var/lib/mysql//wsrep_recovery.BDTAm8' --pid-file='/var/lib/mysql//scratch-recover.pid'
181004 15:48:30 mysqld_safe WSREP: Recovered position 9388319e-c7bd-11e8-b2ce-6e9ec70d9926:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment