Today's coolness: ZFS Snapshots and Reproducible test states

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. 

Time: 1 hour.

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@freshdb

bash# zfs list -t snapshot
NAME                             USED  AVAIL  REFER  MOUNTPOINT
tank2/db0/data@freshdb              0      -  13.5G  -
Time: 8 seconds

Do this as many times as you need. Fresh databases in seconds, not upwards of an hour.

Just wanted to share...

Comments:

Post a Comment:
Comments are closed for this entry.
About

Main Sequence: 1) an astronomy term denoting the lifecycle of a majority of known stars. 2) err @ Sun/Oracle: long-time (since 1988) Sun/Oracle veteran, still shining in an ever-changing high-tech universe

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today