Skip to content

Commit

Permalink
remove gpg file if exist
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyue committed Nov 5, 2013
1 parent 9968770 commit 69fa490
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/backup/storage.rb
Expand Up @@ -69,15 +69,18 @@ def backup_mysql
mysql_config += " --ignore_table=#{table}"
end

backup_file = "#{target_path}/#{key}.sql"

tmpfile = Tempfile.new('mysql.sql')
run_with_changes("ssh #{@ssh_host} 'mysqldump #{mysql_config} > #{tmpfile.path}'",mysql_config) &&
run_with_changes("scp #{@scp_host}:#{tmpfile.path} '#{target_path}/#{key}.sql'") &&
run_with_changes("scp #{@scp_host}:#{tmpfile.path} '#{backup_file}'") &&
run_with_changes("ssh #{@ssh_host} 'rm #{tmpfile.path}'")

check_backuped_mysql(target_path, key) if config.mysql_check and (mysql.check || mysql.check.nil?)

if config.gpg_enable
run_with_changes("gpg --trust-model always -e -r #{config.gpg_id} #{target_path}/#{key}.sql")
system("rm #{backup_file}.gpg") if File.exist?("#{backup_file}.gpg")
run_with_changes("gpg --trust-model always -e -r #{config.gpg_id} -o #{backup_file}.gpg #{backup_file}")
run_with_changes("rm #{target_path}/#{key}.sql")
end
end
Expand Down

0 comments on commit 69fa490

Please sign in to comment.