Exec iterate through array

Hello all, I am looking for a little insight on how to by pass this
error when running my sctipt... any help is greatly appreciated.

mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to
database 'information_schema' when using LOCK TABLES

tempDir = "/mnt/dumpspace"
dumpUser = ""
dumpUserPass = ""

if Dir["#{tempDir}/*"] != nil
  puts "exits"
  FileUtils.rm_rf(Dir.glob("/mnt/dumpspace/*"))
else
  puts "doesn't exist, this should never be true!"
end

date = Time.now.strftime("%m%e%g")
puts date
db = Mysql.real_connect('localhost',dumpUser,dumpUserPass)
puts "Server version: " + db.get_server_info
db.query('show databases').each do |db|
  puts " Dumping - " + db[0] + "\n"
  Dir.mkdir("#{tempDir}/#{db[0]}")
  dump = "mysqldump -u #{dumpUser} -p#{dumpUserPass} #{db[0]} >
#{tempDir}/#{db[0]}_#{date}.sql"
  exec dump
end
db.close

···

--
Posted via http://www.ruby-forum.com/.

Silly question, but does the user 'root'@'localhost' have LOCK TABLES
in their granted permissions?

···

On 26 June 2013 08:14, Micah Seattle <lists@ruby-forum.com> wrote:

Hello all, I am looking for a little insight on how to by pass this
error when running my sctipt... any help is greatly appreciated.

mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to
database 'information_schema' when using LOCK TABLES

tempDir = "/mnt/dumpspace"
dumpUser = ""
dumpUserPass = ""

if Dir["#{tempDir}/*"] != nil
  puts "exits"
  FileUtils.rm_rf(Dir.glob("/mnt/dumpspace/*"))
else
  puts "doesn't exist, this should never be true!"
end

date = Time.now.strftime("%m%e%g")
puts date
db = Mysql.real_connect('localhost',dumpUser,dumpUserPass)
puts "Server version: " + db.get_server_info
db.query('show databases').each do |db|
  puts " Dumping - " + db[0] + "\n"
  Dir.mkdir("#{tempDir}/#{db[0]}")
  dump = "mysqldump -u #{dumpUser} -p#{dumpUserPass} #{db[0]} >
#{tempDir}/#{db[0]}_#{date}.sql"
  exec dump
end
db.close

--
Posted via http://www.ruby-forum.com/.

--
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/

mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to
database 'information_schema' when using LOCK TABLES

Read the mysqldump man page:

       mysqldump does not dump the INFORMATION_SCHEMA database by default. mysqldump dumps
       INFORMATION_SCHEMA only if you name it explicitly on the command line, although currently you must
       also use the --skip-lock-tables option. Before MySQL 5.5 mysqldump silently ignores
       INFORMATION_SCHEMA even if you name it explicitly on the command line.

tempDir = "/mnt/dumpspace"
dumpUser = ""
dumpUserPass = ""

if Dir["#{tempDir}/*"] != nil
  puts "exits"

Typo? "exists" ?

  FileUtils.rm_rf(Dir.glob("/mnt/dumpspace/*"))
else
  puts "doesn't exist, this should never be true!"
end

date = Time.now.strftime("%m%e%g")
puts date
db = Mysql.real_connect('localhost',dumpUser,dumpUserPass)
puts "Server version: " + db.get_server_info
db.query('show databases').each do |db|
  puts " Dumping - " + db[0] + "\n"
  Dir.mkdir("#{tempDir}/#{db[0]}")
  dump = "mysqldump -u #{dumpUser} -p#{dumpUserPass} #{db[0]} >
#{tempDir}/#{db[0]}_#{date}.sql"
  exec dump

`exec` will *replace* your running script and not return to it.

What you want here, is either backticks, system, or all the way to
something like Open3.capture2 or 3.

end
db.close

If you want a much more elegant solution to this and other backup
things, do look at the Backup gem:

Even if you don't use it, read it and learn from it. It's quite an
elegant bit of ruby code.

···

Micah Seattle <lists@ruby-forum.com> wrote:

Aside from the sql permissions, I'm not sure you'll have much luck exec'ing in a loop =]

Sam

···

On 26/06/13 11:46, Matthew Kerwin wrote:

Silly question, but does the user 'root'@'localhost' have LOCK TABLES
in their granted permissions?

On 26 June 2013 08:14, Micah Seattle <lists@ruby-forum.com> wrote:

Hello all, I am looking for a little insight on how to by pass this
error when running my sctipt... any help is greatly appreciated.

mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to
database 'information_schema' when using LOCK TABLES

tempDir = "/mnt/dumpspace"
dumpUser = ""
dumpUserPass = ""

if Dir["#{tempDir}/*"] != nil
   puts "exits"
   FileUtils.rm_rf(Dir.glob("/mnt/dumpspace/*"))
else
   puts "doesn't exist, this should never be true!"
end

date = Time.now.strftime("%m%e%g")
puts date
db = Mysql.real_connect('localhost',dumpUser,dumpUserPass)
puts "Server version: " + db.get_server_info
db.query('show databases').each do |db|
   puts " Dumping - " + db[0] + "\n"
   Dir.mkdir("#{tempDir}/#{db[0]}")
   dump = "mysqldump -u #{dumpUser} -p#{dumpUserPass} #{db[0]} >
#{tempDir}/#{db[0]}_#{date}.sql"
   exec dump
end
db.close

--
Posted via http://www.ruby-forum.com/.

Thanks everyone

···

https://github.com/meskyanichi/backup

--
Posted via http://www.ruby-forum.com/.