Created
July 20, 2012 14:02
-
-
Save mk270/3150892 to your computer and use it in GitHub Desktop.
CLI wrapper for "FLUSH TABLES WITH READ LOCK"; usage mysql_with_ftwrl.rb do_snapshot --db=name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'dbi' | |
db_name = 'db_test' | |
db_user = 'username' | |
db_pass = 'pass1234' | |
db_host = '127.0.0.1' | |
exit_status = nil | |
begin | |
dbh = DBI.connect("DBI:Mysql:#{db_name}:#{db_host}", db_user, db_pass) | |
dbh.select_all('FLUSH TABLES WITH READ LOCK;') | |
system(*ARGV) | |
exit_status = $?.to_i >> 8 | |
rescue DBI::DatabaseError => e | |
puts "error (#{e.err}): #{e.errstr}" | |
exit 1 | |
ensure | |
dbh.select_all('UNLOCK TABLES;') | |
dbh.disconnect if dbh | |
end | |
exit exit_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment