Class: Siba::Encryption::Gpg::Init

Inherits:
Object
  • Object
show all
Includes:
FilePlug, LoggerPlug
Defined in:
lib/siba/plugins/encryption/gpg/init.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FilePlug

#siba_file, siba_file, siba_file=

Methods included from LoggerPlug

close, create, logger, #logger, opened?

Constructor Details

#initialize(options) ⇒ Init

Returns a new instance of Init.



13
14
15
16
17
# 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

Instance Attribute Details

#encryptionObject

Returns the value of attribute encryption.



11
12
13
# File 'lib/siba/plugins/encryption/gpg/init.rb', line 11

def encryption
  @encryption
end

Instance Method Details

#backup(path_to_archive, dest_dir) ⇒ Object

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.



22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object

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



35
36
37
38
39
40
41
42
# 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