I'm using ZFS to take snapshots of running OpenVZ containers.
For MySQL databases I can use
flush tables with read lock to put them in a flushed & locked state. This will put the underlying files in a consistent state and hold any incoming queries until I complete the snapshots, which take at most a couple seconds.
Here is a sample script, without error checking and other housekeeping code:
vz_root=/var/lib/vz/root/$veid mysql_locked=/var/run/mysql_locked # flush & lock MySQL, touch mysql_locked, and wait until it is removed vzctl exec $veid mysql -NB <<-EOF & flush tables with read lock; delimiter ;; system touch $mysql_locked system while test -e $mysql_locked; do sleep 1; done exit EOF # wait for the preceding command to touch mysql_locked while ! test -e $vz_root$mysql_locked; do sleep 1; done # take a snapshot of the VZ filesystem, while MySQL is being held locked zfs snapshot zpool/private/$veid@$(date +"%Y-%m-%d_%H:%M") # unlock MySQL rm -f $vz_root$mysql_locked
Can I do the same thing for an Oracle database?
Is there a command that will flush its tablespaces, put them in a consistent state, suitable for backup, and hold any activity until I unlock it?
I'd rather avoid having to reconfigure Oracle to use ZFS directly as a storage backend, because simple OpenVZ containers suit me very well. In fact I'd rather have some low-maintenance technique, without any complex Oracle setup, if any exists.