Sha256: bdb91a640a8f416ec7e3fd250cbfa4711b8172f3e4d50536e9ff21c8ff6d30c9
Contents?: true
Size: 1.72 KB
Versions: 21
Compression:
Stored size: 1.72 KB
Contents
module EY module Backup class MysqlEngine < Engine register 'mysql' def dump(database_name, basename) file = basename + '.sql' command = "mysqldump #{username_option} #{host_option} #{password_option} #{single_transaction_option(database_name)} #{routines_option} #{database_name}" if gpg? command << " | " << GPGEncryptor.command_for(key_id) file << GPGEncryptor.extension else command << " | " << GZipper.gzip file << GZipper.extension end command << " > #{file}" run(command) file end def load(database_name, file) command = "cat #{file}" if gpg? raise "Cannot load a GPG backup" else command << " | " << GZipper.gunzip end command << " | mysql #{username_option} #{host_option} #{password_option} #{database_name}" run(command) end def routines_option "--routines" end def password_option "-p'#{password}'" unless password.nil? || password.empty? end def host_option "-h#{host}" end def username_option "-u#{username}" end def single_transaction_option(database_name) '--single-transaction' unless db_has_myisam?(database_name) end def db_has_myisam?(database_name) query, stdout = "SELECT 1 FROM information_schema.tables WHERE table_schema='#{database_name}' AND engine='MyISAM' LIMIT 1;", StringIO.new spawn(%Q{mysql #{username_option} #{password_option} #{host_option} -N -e"#{query}"}, stdout) stdout.string.strip == '1' end def suffix /sql\.(gz|gpz)$/ end end end end
Version data entries
21 entries across 21 versions & 1 rubygems