Class: Tms::Backup
Class Method Summary
collapse
Instance Method Summary
collapse
better_attr_accessor, better_attr_reader
Constructor Details
#initialize(path, in_progress = false) ⇒ Backup
Returns a new instance of Backup.
78
79
80
81
|
# File 'lib/tms/backup.rb', line 78
def initialize(path, in_progress = false)
@path = path
@in_progress = in_progress
end
|
Class Method Details
.add_filter_dir(filter_dir) ⇒ Object
39
40
41
|
# File 'lib/tms/backup.rb', line 39
def add_filter_dir(filter_dir)
filter_dirs << File.expand_path(filter_dir)
end
|
.backup_volume ⇒ Object
13
14
15
|
# File 'lib/tms/backup.rb', line 13
def backup_volume
Tms.backup_volume or abort('backup volume not avaliable')
end
|
.backups_dir ⇒ Object
21
22
23
24
25
26
|
# File 'lib/tms/backup.rb', line 21
def backups_dir
unless @backups_dir
self.backups_dir = Path.new(backup_volume) / 'Backups.backupdb' / computer_name
end
@backups_dir
end
|
.backups_dir=(backups_dir) ⇒ Object
27
28
29
30
31
|
# File 'lib/tms/backup.rb', line 27
def backups_dir=(backups_dir)
backups_dir = Path.new(backups_dir)
abort %{backups dir «#{backups_dir}» is not a dir} unless backups_dir.directory?
@backups_dir = backups_dir
end
|
.colorize? ⇒ Boolean
49
50
51
|
# File 'lib/tms/backup.rb', line 49
def colorize?
!colorize.nil? ? colorize : $stdout.tty?
end
|
.computer_name ⇒ Object
17
18
19
|
# File 'lib/tms/backup.rb', line 17
def computer_name
Tms.computer_name or abort('can\'t get computer name')
end
|
.filter_dirs ⇒ Object
33
34
35
|
# File 'lib/tms/backup.rb', line 33
def filter_dirs
@filter_dirs ||= []
end
|
.filter_dirs? ⇒ Boolean
36
37
38
|
# File 'lib/tms/backup.rb', line 36
def filter_dirs?
!filter_dirs.empty?
end
|
.list ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/tms/backup.rb', line 57
def list
@list ||= begin
backups_dir.children.map do |path|
case path.basename.to_s
when /^\d{4}-\d{2}-\d{2}-\d{6}$/
new(path)
when /^\d{4}-\d{2}-\d{2}-\d{6}\.inProgress$/
if show_in_progress?
path.children.select(&:directory?).map do |path_in_progress|
new(path_in_progress, true)
end
end
end
end.flatten.compact.sort
end
end
|
.show_progress? ⇒ Boolean
53
54
55
|
# File 'lib/tms/backup.rb', line 53
def show_progress?
!show_progress.nil? ? show_progress : $stderr.tty?
end
|
Instance Method Details
#<=>(other) ⇒ Object
109
110
111
|
# File 'lib/tms/backup.rb', line 109
def <=>(other)
name <=> other.name
end
|
#completed_in ⇒ Object
93
94
95
|
# File 'lib/tms/backup.rb', line 93
def completed_in
finished_at - started_at
end
|
#finished_at ⇒ Object
90
91
92
|
# File 'lib/tms/backup.rb', line 90
def finished_at
@finished_at ||= Time.at(xattr.get('com.apple.backupd.SnapshotCompletionDate').to_i / 1_000_000.0)
end
|
#name ⇒ Object
83
84
85
|
# File 'lib/tms/backup.rb', line 83
def name
@name ||= in_progress? ? "#{path.dirname.basename}/#{path.basename}" : path.basename.to_s
end
|
#started_at ⇒ Object
87
88
89
|
# File 'lib/tms/backup.rb', line 87
def started_at
@start_date ||= Time.at(xattr.get('com.apple.backupd.SnapshotStartDate').to_i / 1_000_000.0)
end
|