class Siba::Encryption::Gpg::Init

Attributes

encryption[RW]

Public Class Methods

new(options) click to toggle source
# File lib/siba/plugins/encryption/gpg/init.rb, line 13
def initialize(options)
  passphrase = Siba::SibaCheck.options_string(options, "passphrase")
  cipher = Siba::SibaCheck.options_string(options, "cipher", true)
  @encryption = Siba::Encryption::Gpg::Encryption.new passphrase, cipher
end

Public Instance Methods

backup(path_to_archive, dest_dir) click to toggle source

Encrypt backup archive file (path_to_archive) and put it to dest_dir. Return the name of encrypted file. It must begin with archive name and its ending must always be the same.

# File lib/siba/plugins/encryption/gpg/init.rb, line 22
def backup(path_to_archive, dest_dir)
  logger.info "Encrypting backup with 'gpg', cipher: '#{encryption.cipher}'"
  path_to_encrypted_file = encryption.encrypt path_to_archive

  # move encrypted file to dest_dir
  file_name = File.basename path_to_encrypted_file
  dest_file_path = File.join dest_dir, file_name
  siba_file.file_utils_mv path_to_encrypted_file, dest_file_path
  file_name
end
restore(path_to_backup, to_dir) click to toggle source

Decrypt backup file (path_to_backup) to_dir. Return the name of decrypted file.

# File lib/siba/plugins/encryption/gpg/init.rb, line 35
def restore(path_to_backup, to_dir)
  logger.info "Decrypting backup with 'gpg', cipher: '#{encryption.cipher}'"
  decrypted_file_name = File.basename path_to_backup
  decrypted_file_name.gsub! /\.gpg$/, ""
  path_to_decrypted_file = File.join to_dir, decrypted_file_name
  encryption.decrypt path_to_backup, path_to_decrypted_file
  decrypted_file_name
end