This repository has been archived by the owner on Jan 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
backup.rb
77 lines (69 loc) · 2.32 KB
/
backup.rb
1
2
3
4
5
6
7
8
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
77
# Sets up a backup job for each host that pushed data to swift
# The config and setup goes on each vertica node but only one is actually activated to run the job, it starts the job on the others
# This is so the backup is consistent across all 5 nodes and is a core assumption of the vbr tool
include_recipe "python"
require 'zlib'
python_pip 'vertica-swift-backup' do
action :install
end
## Pull the data bags
creds = data_bag_item("vertica", "backup_credentials#{node[:vertica][:cluster_name]}")
#Pull cluster node information, ** This is copied from the cluster recipe which primarily uses this, it is important they match
nodes = data_bag_item("vertica", "nodes#{node[:vertica][:cluster_name]}")['nodes']
ips = []
nodes.each { | node, value| ips.push(value['ip']) }
ips.sort!
## The backup configs
directory node[:vertica][:backup_dir] do
action :create
owner node[:vertica][:dbadmin_user]
group node[:vertica][:dbadmin_group]
mode '775'
end
snapshot_name = node[:domain].gsub('.', '_') + "_#{creds['dbname']}"
if node[:fqdn] == nodes.keys[0] # cron runs at least 1 hour before on the box which runs vbr
run_hour = '3'
run_vbr = true
else
run_hour = '5'
run_vbr = false
end
template "/opt/vertica/config/#{creds['dbname']}_backup.yaml" do
action :create
source 'backup.yaml.erb'
owner node[:vertica][:dbadmin_user]
group node[:vertica][:dbadmin_group]
mode '600'
variables(
:dbname => creds['dbname'],
:run_vbr => run_vbr,
:snapshot_name => snapshot_name,
:swift_user => creds['swift_user'],
:swift_tenant => creds['swift_tenant'],
:swift_key => creds['swift_key'],
:url => creds['url'],
:swift_region => creds['swift_region'],
:vbr_config => "/opt/vertica/config/#{creds['dbname']}_backup.ini"
)
end
template "/opt/vertica/config/#{creds['dbname']}_backup.ini" do
action :create
source 'backup.ini.erb'
owner node[:vertica][:dbadmin_user]
group node[:vertica][:dbadmin_group]
mode '600'
variables(
:dbname => creds['dbname'],
:dbuser => creds['dbuser'],
:dbpass => creds['dbpass'],
:ips => ips,
:snapshot_name => snapshot_name
)
end
cron 'vertica_backup' do
action :create
user node[:vertica][:dbadmin_user]
hour run_hour
minute Zlib.crc32(node[:fqdn]) % 60
command "/usr/local/bin/vertica_backup /opt/vertica/config/#{creds['dbname']}_backup.yaml"
end