Skip to content

Commit

Permalink
make gpg works on new server
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyue committed Sep 1, 2015
1 parent 61795bf commit f692bf3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/backup/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ def backup_mysql

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

if config.gpg_enable
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
encrypt_with_gpg(backup_file, gpg_id, backup_name) if config.gpg_enable
end
end

Expand All @@ -92,7 +88,7 @@ def backup_postgresql
FileUtils.mkdir_p target_path

@server_config.postgresql.map do |key, postgresql|
postgresql_config = " "
postgresql_config = ""
postgresql_config += " -d #{postgresql.databases.split("\n").join(' ')}" if postgresql.databases
postgresql_config += " -U #{postgresql.user}" if postgresql.user
postgresql_config += " -h #{postgresql.host}" if postgresql.host
Expand All @@ -116,12 +112,18 @@ def backup_postgresql

check_backuped_postgresql(target_path, key) if config.postgresql_check and (postgresql.check || postgresql.check.nil?)

if config.gpg_enable
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
encrypt_with_gpg(backup_file, gpg_id, backup_name) if config.gpg_enable
end
end

def encrypt_with_gpg(backup_file, gpg_id, backup_name)
if !Backup::Main.run("gpg --search-keys --keyserver hkp://keys.gnupg.net #{gpg_id}")
Backup::Main.run("gpg --keyserver hkp://keys.gnupg.net --recv #{gpg_id}")
end

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

def check_backuped_mysql(target_path, key)
Expand Down

0 comments on commit f692bf3

Please sign in to comment.