Last active
August 2, 2024 07:19
-
-
Save karolyi/48e0e7909ae67e9d8f2503bfc3c79225 to your computer and use it in GitHub Desktop.
Fast backup/restore mysql databases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
mariabackup --stream=xbstream --backup --user root|pigz >mariadb-backup.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash -x | |
# OSX: execute as user | |
# Linux: execute as root | |
MY_DIR=$(cd $(dirname ${BASH_SOURCE[0]});pwd) | |
cd $MY_DIR | |
MARIABACKUP=$(which mariabackup) | |
mkdir mariadb-restore | |
service mysql stop | |
# OSX: mysql.server stop | |
rm -rf /var/lib/mysql/* | |
# OSX: rm -rf /usr/local/var/mysql/* | |
unpigz -c mariadb-backup.gz|mbstream -C mariadb-restore -x -p 4 | |
$MARIABACKUP --prepare --target-dir mariadb-restore/ --user root | |
$MARIABACKUP --move-back --target-dir mariadb-restore/ --user root | |
# Linux only, running as root | |
chown -R mysql:mysql /var/lib/mysql/ | |
rm -rf mariadb-restore/ | |
# OSX: mysql.server start | |
service mysql start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment