Class: Siba::SibaTasks
- Inherits:
-
Object
show all
- Includes:
- FilePlug
- Defined in:
- lib/siba/tasks/siba_tasks.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from FilePlug
#siba_file, siba_file, siba_file=
Constructor Details
#initialize(options, path_to_options_yml, skip_source_task) ⇒ SibaTasks
Returns a new instance of SibaTasks.
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/siba/tasks/siba_tasks.rb', line 10
def initialize(options, path_to_options_yml, skip_source_task)
@path_to_options_yml = path_to_options_yml
raise 'Options are not loaded' if options.nil?
@tasks = {}
Siba::Plugins::CATEGORIES.each do |category|
next if category == "source" && skip_source_task
@tasks[category] = SibaTask.new options, category
end
end
|
Instance Attribute Details
#tasks ⇒ Object
Returns the value of attribute tasks.
8
9
10
|
# File 'lib/siba/tasks/siba_tasks.rb', line 8
def tasks
@tasks
end
|
Class Method Details
.backup_name(now = nil) ⇒ Object
Instance Method Details
#backup ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/siba/tasks/siba_tasks.rb', line 21
def backup
siba_file.run_this "backup" do
@tasks["source"].backup source_dir
raise Siba::Error, "There are no files to backup" if Siba::FileHelper.dir_empty? source_dir
OptionsBackup.save_options_backup path_to_options_yml, source_dir
archive_file_name = @tasks["archive"].backup source_dir, archive_dir, SibaTasks.backup_name
unless archive_file_name =~ /^#{SibaTasks.backup_name}/
raise Siba::Error, "Archive file name must begin with: #{SibaTasks.backup_name}"
end
path_to_archive = File.join archive_dir, archive_file_name
unless siba_file.file_file? path_to_archive
raise Siba::Error, "Failed to create archive file: #{path_to_archive}"
end
name_of_encrypted_file = @tasks["encryption"].backup path_to_archive, encryption_dir
unless name_of_encrypted_file =~ /^#{archive_file_name}/
raise Siba::Error, "File name of encrypted file must begin with: #{archive_file_name}"
end
path_to_backup = File.join encryption_dir, name_of_encrypted_file
unless siba_file.file_file? path_to_backup
raise Siba::Error, "Failed to encrypt backup: #{path_to_backup}"
end
@tasks["destination"].backup path_to_backup
end
end
|
#get_backups_list ⇒ Object
73
74
75
|
# File 'lib/siba/tasks/siba_tasks.rb', line 73
def get_backups_list
@tasks["destination"].plugin.get_backups_list Siba.backup_name
end
|
#restore(backup_file_name) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/siba/tasks/siba_tasks.rb', line 49
def restore(backup_file_name)
siba_file.run_this do
@tasks["destination"].restore backup_file_name, destination_dir
path_to_backup = File.join destination_dir, backup_file_name
unless siba_file.file_file? path_to_backup
raise Siba::Error, "Failed to get backup from destination: #{backup_file_name}"
end
archive_file_name = @tasks["encryption"].restore path_to_backup, encryption_dir
path_to_archive = File.join encryption_dir, archive_file_name
unless siba_file.file_file? path_to_archive
raise Siba::Error, "Failed to get archive file: #{path_to_archive}"
end
@tasks["archive"].restore path_to_archive, source_dir
if Siba::FileHelper.dir_empty? source_dir
raise Siba::Error, "Failed to extract archive: #{path_to_archive}"
end
@tasks["source"] = OptionsBackup.load_source_from_backup source_dir if @tasks["source"].nil?
@tasks["source"].restore source_dir
end
end
|