Class: Muck::Archive
Constant Summary
collapse
- MAPPING =
{
:hourly => 'YYYY-mm-dd-HH',
:daily => "YYYY-mm-dd",
:monthly => 'YYYY-mm',
:yearly => 'YYYY'
}
Instance Method Summary
collapse
Methods included from Utils
#blue, #green, #pink, #red, #yellow
Methods included from Logging
#log, #logger
Constructor Details
#initialize(database, name, maximum) ⇒ Archive
Returns a new instance of Archive.
18
19
20
21
22
|
# File 'lib/muck/archive.rb', line 18
def initialize(database, name, maximum)
@database = database
@name = name
@maximum = maximum
end
|
Instance Method Details
#create_archive(backup) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/muck/archive.rb', line 37
def create_archive(backup)
logger.info "Archiving #{blue @name} backup for #{blue @database.name} on #{blue @database.server.hostname}"
logger.info "Using backup from #{blue backup[:path]}"
filename = filename_for(backup[:path])
archive_path = File.join(export_path, filename)
FileUtils.mkdir_p(File.dirname(archive_path))
if system("ln -f #{backup[:path]} #{archive_path}")
logger.info "Successfully stored archive at #{green archive_path}"
else
logger.error red("Couldn't store archive at #{archive_path}")
end
end
|
#export_path ⇒ Object
24
25
26
|
# File 'lib/muck/archive.rb', line 24
def export_path
File.join(@database.export_path, @name.to_s)
end
|
#run ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/muck/archive.rb', line 28
def run
if last_backup = @database.manifest[:backups].last
create_archive(last_backup)
tidy
else
log.info "There is no backup to archive"
end
end
|
#tidy ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/muck/archive.rb', line 50
def tidy
files = Dir[File.join(export_path, '*')].sort.reverse.drop(@maximum)
files.each do |file|
if system("rm #{file}")
logger.info "Tidied #{green file}"
else
logger.error red("Couldn't remove un-retained file at #{file}")
end
end
end
|