From: Tamara Temple Date: 2013-06-26T10:30:59+09:00 Subject: Re: exec iterate through array Micah Seattle wrote: > 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: https://github.com/meskyanichi/backup Even if you don't use it, read it and learn from it. It's quite an elegant bit of ruby code.