Skip to content

Instantly share code, notes, and snippets.

@mk270
Created July 20, 2012 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk270/3150892 to your computer and use it in GitHub Desktop.
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
#!/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