Notes: I wrote this documentation around 2013 as internal documentation at Weever Apps for setting up RAID-Z as a method of making very quick backups of MySQL. Since we no longer use this setup and the documentation will never be used again, I felt it might be a good idea to post it out there for those who might find some use in it. Using RAID-Z for MySQL was amazing, and never failed us, and allowed hourly snapshot-based backups with no downtime. We've since moved to AWS RDS instances though.
This will be part of multiple posts that combined will allow one to build a RAID-Z setup for MySQL. Or, at least it used to be able to! While this is geared towards Azure, I'm sure it would work anywhere.
As I add more parts over the next few days I'll add links here.
- Installing ZFS on CentOS
- Creating a RAID-Z Drive for MySQL with ZFS on CentOS
- Setting up RAID-Z for use in a MySQL Master-Master Replicator Pattern
- Creating a ZFS Image of a MySQL Data Directory
Creating a ZFS image for backup is pretty easy.
First, a ZFS snapshot must exist. If one does not already, create one.
If this is for MySQL and the tables in MySQL are using MyISAM, make sure to either turn off the server briefly, or, lock the tables momentarily. In my experience these locks just delay writes until unlocked, and snapshotting is surprisingly quick in ZFS.
FLUSH TABLES WITH READ LOCK;
This example will assume you're grabbing the MySQL data directory, which would be stored in a tank called
sqlstorage, with filesystem
data. Adjust if your setup is differently named.
zfs snapshot sqlstorage/data@now
Now we can unlock the tables or start the MySQL server up again.
All we need is one command to send this snapshot to a file. Depending on the size of the file system, this could take a while.
zfs send sqlstorage/data@now >/tmp/sqlstorage-backup.zfs
Is something badly out of date? Did this work for you? Please post a comment to help others who might use this for guidance.