Skip to content

Instantly share code, notes, and snippets.

@corny
Last active January 19, 2017 12:04
Show Gist options
  • Select an option

  • Save corny/f4fcb9273295d4176e4d7c4a5507af7f to your computer and use it in GitHub Desktop.

Select an option

Save corny/f4fcb9273295d4176e4d7c4a5507af7f to your computer and use it in GitHub Desktop.
Create a consistent MariaDB/MySQL snapshot with ZFS
#!/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