Class: BackupFoundation::Item::Base
- Inherits:
-
Object
- Object
- BackupFoundation::Item::Base
show all
- Defined in:
- lib/backup_foundation/item/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(options, tmpdir, encryption_key = nil) ⇒ Base
Returns a new instance of Base.
4
5
6
7
8
|
# File 'lib/backup_foundation/item/base.rb', line 4
def initialize(options, tmpdir, encryption_key=nil)
@options = options
@encryption_key = encryption_key
@tmpdir = tmpdir
end
|
Instance Method Details
#decrypt_if_needed_and_restore(command, infile_path) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/backup_foundation/item/base.rb', line 29
def decrypt_if_needed_and_restore(command, infile_path)
if @encryption_key
IO.pipe do |rp, wp|
wp.puts @encryption_key
system "cat #{infile_path} | gpg --yes --batch --passphrase-fd=3 -q -r -d | gunzip -c | #{command}", 3 => rp
end
else
`gunzip -c #{infile_path} | #{command}`
end
end
|
#dump_and_encrypt_if_needed(command) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/backup_foundation/item/base.rb', line 18
def dump_and_encrypt_if_needed(command)
if @encryption_key
IO.pipe do |rp, wp|
wp.puts @encryption_key
system output_to_file("#{command} | gzip -cf | gpg --yes --batch --passphrase-fd=3 -q -r -e -c"), 3 => rp
end
else
`#{output_to_file("#{command} | gzip -cf")}`
end
end
|
#outfile_path ⇒ Object
10
11
12
|
# File 'lib/backup_foundation/item/base.rb', line 10
def outfile_path
"#{@tmpdir}/#{File.basename(@options[:database] || @options[:name])}.gz#{'.gpg' if @encryption_key}"
end
|
#output_to_file(command) ⇒ Object
14
15
16
|
# File 'lib/backup_foundation/item/base.rb', line 14
def output_to_file(command)
"#{command} > #{outfile_path}"
end
|