-
-
Save gautiermichelin/cc8103a6401e931392e83e42e3138b30 to your computer and use it in GitHub Desktop.
Fast backup/restore mysql databases
This file contains 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 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 | |
# just in case... | |
mv /var/lib/mysql.bak /var/lib/mysql.bak2 | |
# backuping /var/lib/mysql | |
mv /var/lib/mysql /var/lib/mysql.bak | |
mkdir -p /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