Commit 4ac068809524323d9e3a08779856947f6b6923b7
Committed by
Earth Ugat

1 parent
c197ede2
Version v0.5.1. Make some attributes optional.
Showing
6 changed files
with
47 additions
and
16 deletions
1 | +## 0.5.1 - 2016-12-13 | ||
2 | +### Changed | ||
3 | +- Attributes :bak_filename and :bak_maxcopies are now optional in the 'db_map' specifications. | ||
4 | +### Added | ||
5 | +- Node attribute node['cfe-mariadb']['reload']['force'] will now override idempotent run for recipe 'reload_from_s3' if set to true. | ||
6 | + | ||
1 | ## 0.5.0 | 7 | ## 0.5.0 |
2 | ### Added | 8 | ### Added |
3 | - Add boolean attributes ':backup' and ':reload' to db_map. They give the option of whether or not to include that database when using the 'backup2s3' and 'reload_from_s3' recipes, respectively. | 9 | - Add boolean attributes ':backup' and ':reload' to db_map. They give the option of whether or not to include that database when using the 'backup2s3' and 'reload_from_s3' recipes, respectively. |
@@ -67,6 +67,12 @@ Ubuntu 14.04 | @@ -67,6 +67,12 @@ Ubuntu 14.04 | ||
67 | <td><tt>nil</tt></td> | 67 | <td><tt>nil</tt></td> |
68 | </tr> | 68 | </tr> |
69 | <tr> | 69 | <tr> |
70 | + <td><tt>['cfe-mariadb']['reload']['false']</tt></td> | ||
71 | + <td>Boolean</td> | ||
72 | + <td>If the recipe 'reload_from_s3' is run, reload the databases even if it has already been done by a previous run of this recipe.</td> | ||
73 | + <td><tt>false</tt></td> | ||
74 | + </tr> | ||
75 | + <tr> | ||
70 | <td><tt>['cfe-mariadb']['encrypt']['priv_key']</tt></td> | 76 | <td><tt>['cfe-mariadb']['encrypt']['priv_key']</tt></td> |
71 | <td>String</td> | 77 | <td>String</td> |
72 | <td>Contents of the private key file used by recipe `reload_from_s3` if encrypted backups are used.</td> | 78 | <td>Contents of the private key file used by recipe `reload_from_s3` if encrypted backups are used.</td> |
@@ -23,10 +23,10 @@ | @@ -23,10 +23,10 @@ | ||
23 | # 'example_db_name' => { | 23 | # 'example_db_name' => { |
24 | # :db_user => 'example_db_username', | 24 | # :db_user => 'example_db_username', |
25 | # :db_pass => 'example_db_password', | 25 | # :db_pass => 'example_db_password', |
26 | -# :bak_filename => 'example_db_name.sql', | ||
27 | -# :bak_maxcopies => 30 | ||
28 | 26 | ||
29 | ## Optional: | 27 | ## Optional: |
28 | +# :bak_filename => 'example_db_name.sql', # Defaults to {dbname}.sql | ||
29 | +# :bak_maxcopies => 30 | ||
30 | # :char_set => 'utf8', | 30 | # :char_set => 'utf8', |
31 | # :collate => 'utf8_general_ci', | 31 | # :collate => 'utf8_general_ci', |
32 | # :bak_encrypted => false, | 32 | # :bak_encrypted => false, |
@@ -73,6 +73,7 @@ default['cfe-mariadb']['backup']['logrotate']['options'] = %w{ | @@ -73,6 +73,7 @@ default['cfe-mariadb']['backup']['logrotate']['options'] = %w{ | ||
73 | notifempty | 73 | notifempty |
74 | } | 74 | } |
75 | 75 | ||
76 | +default['cfe-mariadb']['reload']['force'] = false | ||
76 | default['cfe-mariadb']['reload']['file_stamp'] = | 77 | default['cfe-mariadb']['reload']['file_stamp'] = |
77 | "#{node['mariadb']['configuration']['path']}/reloaded.stamp" | 78 | "#{node['mariadb']['configuration']['path']}/reloaded.stamp" |
78 | 79 |
@@ -4,7 +4,7 @@ maintainer_email 'sysadmin @ chromedia.com' | @@ -4,7 +4,7 @@ maintainer_email 'sysadmin @ chromedia.com' | ||
4 | license 'Apache License' | 4 | license 'Apache License' |
5 | description 'Simplifies setup of MariaDB in Chromedia.' | 5 | description 'Simplifies setup of MariaDB in Chromedia.' |
6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) | 6 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) |
7 | -version '0.5.0' | 7 | +version '0.5.1' |
8 | 8 | ||
9 | { | 9 | { |
10 | 'mariadb' => '0.3.1', | 10 | 'mariadb' => '0.3.1', |
@@ -31,7 +31,9 @@ manual_creds = node['cfe-mariadb'].has_key?('reload') && | @@ -31,7 +31,9 @@ manual_creds = node['cfe-mariadb'].has_key?('reload') && | ||
31 | tmp_dir = ::File.join(Chef::Config[:file_cache_path], 'db_dumps') | 31 | tmp_dir = ::File.join(Chef::Config[:file_cache_path], 'db_dumps') |
32 | priv_key_file = "#{tmp_dir}/priv.key" | 32 | priv_key_file = "#{tmp_dir}/priv.key" |
33 | 33 | ||
34 | -unless ::File.exist?(node['cfe-mariadb']['reload']['file_stamp']) | 34 | +if node['cfe-mariadb']['reload']['force'] || |
35 | + !::File.exist?(node['cfe-mariadb']['reload']['file_stamp']) | ||
36 | + | ||
35 | directory(tmp_dir) { recursive true } | 37 | directory(tmp_dir) { recursive true } |
36 | 38 | ||
37 | file priv_key_file do | 39 | file priv_key_file do |
@@ -50,8 +52,9 @@ unless ::File.exist?(node['cfe-mariadb']['reload']['file_stamp']) | @@ -50,8 +52,9 @@ unless ::File.exist?(node['cfe-mariadb']['reload']['file_stamp']) | ||
50 | end | 52 | end |
51 | 53 | ||
52 | unless dbx.has_key?(:reload) && dbx[:reload] == false | 54 | unless dbx.has_key?(:reload) && dbx[:reload] == false |
53 | - keyname = "#{dbx[:bak_filename]}.gz#{dbx[:bak_encrypted] ? '.enc' : ''}" | ||
54 | - filepath = "#{tmp_dir}/#{dbx[:bak_filename]}" | 55 | + bfname = dbx[:bak_filename] || "#{dbx_name}.sql" |
56 | + keyname = "#{bfname}.gz#{dbx[:bak_encrypted] ? '.enc' : ''}" | ||
57 | + filepath = "#{tmp_dir}/#{bfname}" | ||
55 | 58 | ||
56 | awscli_s3_file "#{tmp_dir}/#{keyname}" do | 59 | awscli_s3_file "#{tmp_dir}/#{keyname}" do |
57 | region node['cfe-mariadb']['s3_region'] | 60 | region node['cfe-mariadb']['s3_region'] |
@@ -84,8 +87,11 @@ unless ::File.exist?(node['cfe-mariadb']['reload']['file_stamp']) | @@ -84,8 +87,11 @@ unless ::File.exist?(node['cfe-mariadb']['reload']['file_stamp']) | ||
84 | file("#{filepath}.gz.enc") { action :nothing } | 87 | file("#{filepath}.gz.enc") { action :nothing } |
85 | file(filepath) { action :nothing } | 88 | file(filepath) { action :nothing } |
86 | 89 | ||
87 | - file node['cfe-mariadb']['reload']['file_stamp'] do | 90 | + stamp = node['cfe-mariadb']['reload']['file_stamp'] |
91 | + file stamp do | ||
88 | content %x{ date +"%FT%T" } | 92 | content %x{ date +"%FT%T" } |
93 | + only_if "test -d #{::File.dirname(stamp)} || "\ | ||
94 | + "mkdir -p #{::File.dirname(stamp)}" | ||
89 | end | 95 | end |
90 | end | 96 | end |
91 | end | 97 | end |
@@ -107,6 +107,9 @@ upload_to_s3() { | @@ -107,6 +107,9 @@ upload_to_s3() { | ||
107 | } | 107 | } |
108 | 108 | ||
109 | # First, perform mysqldump on each database (and encrypt if desired): | 109 | # First, perform mysqldump on each database (and encrypt if desired): |
110 | +# export_db mydb dbuser 'dbpass' mydb.sql | ||
111 | +# compress_backup_file mydb.sql | ||
112 | +# encrypt_file mydb.sql.gz | ||
110 | 113 | ||
111 | <% @db_map.each do |db| -%> | 114 | <% @db_map.each do |db| -%> |
112 | <% if db.is_a?(Array) -%> | 115 | <% if db.is_a?(Array) -%> |
@@ -116,26 +119,35 @@ upload_to_s3() { | @@ -116,26 +119,35 @@ upload_to_s3() { | ||
116 | <% db_name = db[:db_name] -%> | 119 | <% db_name = db[:db_name] -%> |
117 | <% end -%> | 120 | <% end -%> |
118 | <% unless db.has_key?(:backup) && db[:backup] == false -%> | 121 | <% unless db.has_key?(:backup) && db[:backup] == false -%> |
119 | -export_db <%= db_name %> <%= db[:db_user] %> '<%= db[:db_pass] %>' <%= db[:bak_filename] %> | ||
120 | -compress_backup_file <%= db[:bak_filename] %> | 122 | +<% bfname = db[:bak_filename] || "#{db_name}.sql" -%> |
123 | +export_db <%= db_name %> <%= db[:db_user] %> '<%= db[:db_pass] %>' <%= bfname %> | ||
124 | +compress_backup_file <%= bfname %> | ||
121 | <% if db[:bak_encrypted] -%> | 125 | <% if db[:bak_encrypted] -%> |
122 | -encrypt_file <%= db[:bak_filename] %>.gz | 126 | +encrypt_file <%= bfname %>.gz |
123 | <% end -%> | 127 | <% end -%> |
124 | <% end -%> | 128 | <% end -%> |
125 | <% end -%> | 129 | <% end -%> |
126 | 130 | ||
127 | # Then upload the backup files one by one: | 131 | # Then upload the backup files one by one: |
132 | +# increment_backup_names mydb.sql.gz.enc 30 | ||
133 | +# upload_to_s3 mydb.sql.gz.enc | ||
128 | 134 | ||
129 | <% @db_map.each do |db| -%> | 135 | <% @db_map.each do |db| -%> |
130 | -<% if db.is_a?(Array) then db = db[1] end -%> | ||
131 | -<% if db[:bak_encrypted] -%> | ||
132 | -<% bfname = "#{db[:bak_filename]}.gz.enc" -%> | 136 | +<% if db.is_a?(Array) -%> |
137 | +<% db_name = db[0] -%> | ||
138 | +<% db = db[1] -%> | ||
133 | <% else -%> | 139 | <% else -%> |
134 | -<% bfname = "#{db[:bak_filename]}.gz" -%> | 140 | +<% db_name = db[:db_name] -%> |
135 | <% end -%> | 141 | <% end -%> |
136 | <% unless db.has_key?(:backup) && db[:backup] == false -%> | 142 | <% unless db.has_key?(:backup) && db[:backup] == false -%> |
137 | -increment_backup_names <%= bfname %> <%= db[:bak_maxcopies] %> | ||
138 | -upload_to_s3 <%= bfname %> | 143 | +<% bfname = db[:bak_filename] || "#{db_name}.sql" -%> |
144 | +<% if db[:bak_encrypted] -%> | ||
145 | +<% fullname = "#{bfname}.gz.enc" -%> | ||
146 | +<% else -%> | ||
147 | +<% fullname = "#{bfname}.gz" -%> | ||
148 | +<% end -%> | ||
149 | +increment_backup_names <%= fullname %> <%= db[:bak_maxcopies] || 30 %> | ||
150 | +upload_to_s3 <%= fullname %> | ||
139 | 151 | ||
140 | <% end -%> | 152 | <% end -%> |
141 | <% end -%> | 153 | <% end -%> |