By user12618891 on Sep 23, 2008
I had a lovely 'aha' moment today. This 'aha' is nothing new, except to me. Today, I tried ZFS snapshots for the first time, and it made my life SO much easier! My thanks to colleague Tom Daly for the suggestion!
We're testing Drupal on Webstack on OpenSolaris. The MySQL database we're using totals about 20GB on disk - not big, but heretofore it was created via a script of MySQL commands, including lots of inserts. To populate the database to a 'fresh' state took about 50 minutes on a Sun SPARC Enterprise T5120.
"Why not try ZFS rollback," asks Tom, nonchalantly. Ding! Aha!
OpenSolaris uses ZFS for everything, even booting. It's the default filesystem type. Our database resides on a ZFS mount (in a Zone, no less, back-mounted from the global zone!). This is a perfect use of the ZFS 'snapshot' and 'rollback' commands. To wit:
First, we need re-instantiate the database only once, and get it to just the place we want as our 'unsullied starting-point' database.
Snapshot the ZFS mount in the global zone (before the '@' is the ZFS volume, after is the snapshot name):
bash# zfs snapshot /tank2/db0/data@freshdb bash# zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT tank2/db0/data@freshdb 0 - 13.5G
Time: 10 seconds
Test to your heart's content, mess up the database all your want. Ready for a fresh, unspoiled MySQL database? Well, just roll it back!
bash# zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT tank2/db0/data@freshdb 166M - 13.5G -
bash# zfs rollback /tank2/db0/data@freshdbbash# zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT tank2/db0/data@freshdb 0 - 13.5G -
Do this as many times as you need. Fresh databases in seconds, not upwards of an hour.
Just wanted to share...