9
10
11
12
13
14
15
16
17
18
19
20
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/aptible/cli/subcommands/backup_retention_policy.rb', line 9
def self.included(thor)
thor.class_eval do
include Helpers::Environment
include Term::ANSIColor
desc 'backup_retention_policy [ENVIRONMENT_HANDLE]',
'Show the current backup retention policy for the environment'
define_method 'backup_retention_policy' do |env|
account = ensure_environment(environment: env)
policy = account.backup_retention_policies.first
unless policy
policy = Aptible::Api::BackupRetentionPolicy.new
policy.attributes[:id] = 'default'
policy.attributes[:daily] = 90
policy.attributes[:monthly] = 72
policy.attributes[:yearly] = 0
policy.attributes[:make_copy] = true
policy.attributes[:keep_final] = true
end
Formatter.render(Renderer.current) do |root|
root.object do |node|
ResourceFormatter.inject_backup_retention_policy(
node, policy, account
)
end
end
end
desc 'backup_retention_policy:set [ENVIRONMENT_HANDLE] ' \
'[--daily DAILY_BACKUPS] [--monthly MONTHLY_BACKUPS] ' \
'[--yearly YEARLY_BACKUPS] [--make-copy|--no-make-copy] ' \
'[--keep-final|--no-keep-final]',
"Set the environemnt's backup retention policy"
option :daily, type: :numeric,
desc: 'Number of daily backups to retain',
default: 90
option :monthly, type: :numeric,
desc: 'Number of monthly backups to retain',
default: 72
option :yearly, type: :numeric,
desc: 'Number of yarly backups to retain',
default: 0
option :make_copy, type: :boolean,
desc: 'If backup copies should be created',
default: true
option(
:keep_final,
type: :boolean,
desc: 'If final backups should be kept when databases are '\
'deprovisioned',
default: true
)
define_method 'backup_retention_policy:set' do |env|
account = ensure_environment(environment: env)
policy = account.create_backup_retention_policy!(**options)
Formatter.render(Renderer.current) do |root|
root.object do |node|
ResourceFormatter.inject_backup_retention_policy(
node, policy.reload, account
)
end
end
end
end
end
|