Class: CKnife::CKnifeMysql
- Inherits:
-
Thor
- Object
- Thor
- CKnife::CKnifeMysql
- Defined in:
- lib/cknife/cknife_mysql.rb
Instance Method Summary collapse
Instance Method Details
#capture ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cknife/cknife_mysql.rb', line 70 def capture file_name = "db" + Time.now.strftime("%Y%m%d%H%M%S") + ".sql" if File.exists?(file_name) say("File already exists: #{file_name}.", :red) end command_line.with_option_file do |c| c.execute "mysqldump #{} #{conf[:database]} --add-drop-database --result-file=#{file_name}" do say("Captured #{file_name}.") end end end |
#console ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cknife/cknife_mysql.rb', line 45 def console if !File.exists?(option_file) if ![:myfile] say("You must prepare a #{option_file} file for this command, or use --myfile to have this tool create it for you. Alternatively, you can create a #{option_file} file with the myfile command and delete it later with the dmyfile command.") return end command_line.write_option_file end dc(mysql_easy) if [:verbose] exec(mysql_easy) end |
#dmyfile ⇒ Object
65 66 67 |
# File 'lib/cknife/cknife_mysql.rb', line 65 def dmyfile command_line.delete_opt_file end |
#myfile ⇒ Object
60 61 62 |
# File 'lib/cknife/cknife_mysql.rb', line 60 def myfile command_line.create_opt_file("Connect command: #{mysql_easy}") end |
#restore ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cknife/cknife_mysql.rb', line 86 def restore to_restore = [:filename] if [:filename] if to_restore.nil? files = Dir["db*.sql"] with_mtime = files.map { |f| [f, File.mtime(f)] } with_mtime.sort! { |a,b| a.last <=> b.last } files = with_mtime.map(&:first) to_restore = files.last end if to_restore.nil? say("No backups file to restore. None given on the command line and none could be found in the CWD.", :red) return else if !yes?("Restore #{to_restore}?", :green) return end end command_line.with_option_file do |c| say("Doing restore...") c.execute("mysql #{} #{conf[:database]}", "source #{to_restore};") do say("Restored #{to_restore}") end end end |