Last active
October 27, 2016 02:14
-
-
Save ioquatix/f0b2f2d8c58b7fa4b840ef46c2626f16 to your computer and use it in GitHub Desktop.
Simple MySQL backup script built on percona xtrabackup
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 ruby | |
# In order to use this script, you need a backup user: | |
# CREATE USER backup@localhost; | |
# GRANT SELECT, USAGE, PROCESS, RELOAD, CLIENT REPLICATION ON *.* TO backup@localhost; | |
require 'fileutils' | |
BACKUP_DIR = "/srv/mysql" | |
MYSQL = "/usr/bin/mysql" | |
XTRABACKUP = "/usr/bin/xtrabackup" | |
DATABASES = `mysql -u backup -e "SHOW DATABASES"`.split(/\s+/).grep_v(/Database|_schema|_test|_restore/) | |
FileUtils::Verbose.rm_rf Dir.glob File.join(BACKUP_DIR, '*') | |
system(XTRABACKUP, "--backup", "--user=backup", "--databases", DATABASES.join(' '), "--compress", "--compact", "--target-dir", BACKUP_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment