Last active
January 19, 2017 12:04
-
-
Save corny/f4fcb9273295d4176e4d7c4a5507af7f to your computer and use it in GitHub Desktop.
Create a consistent MariaDB/MySQL snapshot with ZFS
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 python | |
| # | |
| # ./$scriptname zroot/var/mysql@$(date +"%FT%H:%M") | |
| # | |
| # Dependencies for FreeBSD: | |
| # pkg install py27-mysql-connector-python2 | |
| import mysql.connector | |
| import subprocess | |
| import sys | |
| cnx = mysql.connector.connect(user='root', unix_socket='/var/run/mysqld/mysqld.sock') | |
| cursor = cnx.cursor() | |
| cursor.execute('FLUSH TABLES WITH READ LOCK') | |
| subprocess.call(['zfs', 'snapshot', sys.argv[1]]) | |
| cursor.execute('UNLOCK TABLES') | |
| cnx.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment