-
-
Save djrobby/82da5e55cf0a56d17a7da56dae3fb2fd to your computer and use it in GitHub Desktop.
MySQL/MariaDB Backup/Restore Scripts
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