Commit b1c36c6ab0f5b0324a98c2f562ac60fd3ceeabac

Authored by nollieheel
Committed by Earth Ugat
1 parent 20fb182a

Bump to v0.2.1

  1 +# 0.2.1
  2 +
  3 +Recipe reload_from_s3 now properly downloads a .gz file, instead of .tar.gz.
  4 +
1 # 0.2.0 5 # 0.2.0
2 6
3 Use MariaDB 10.0 7 Use MariaDB 10.0
@@ -115,7 +115,7 @@ This will install the backup script and also enable a cronjob to regularly run t @@ -115,7 +115,7 @@ This will install the backup script and also enable a cronjob to regularly run t
115 115
116 ### cfe-mariadb::reload_from_s3 116 ### cfe-mariadb::reload_from_s3
117 117
118 -Kind of the reverse of `backup2s3`. Download a tarball of a MySQL dump file from an S3 bucket, then load it up into a database. Do this for every database given in `node['cfe-mariadb']['db_map']`. 118 +Kind of the reverse of `backup2s3`. Download a gzip of a MySQL dump file from an S3 bucket, then load it up into a database. Do this for every database given in `node['cfe-mariadb']['db_map']`.
119 119
120 This recipe assumes the node is using an EC2 role that can access the given S3 bucket. Otherwise, enter the AWS credentials in `node.default['cfe-mariadb']['reload']['aws_access_key_id']` and `node.default['cfe-mariadb']['reload']['aws_secret_access_key']`. 120 This recipe assumes the node is using an EC2 role that can access the given S3 bucket. Otherwise, enter the AWS credentials in `node.default['cfe-mariadb']['reload']['aws_access_key_id']` and `node.default['cfe-mariadb']['reload']['aws_secret_access_key']`.
121 ## License and Authors 121 ## License and Authors
@@ -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.2.0' 7 +version '0.2.1'
8 8
9 { 9 {
10 'mariadb' => '0.3.1', 10 'mariadb' => '0.3.1',
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 # limitations under the License. 18 # limitations under the License.
19 # 19 #
20 20
21 -# Download a tarball of a MySQL dump from an S3 bucket, 21 +# Download the gzip of a MySQL dump from an S3 bucket,
22 # then load it up into a (preferably empty) database. 22 # then load it up into a (preferably empty) database.
23 23
24 include_recipe 'awscli' 24 include_recipe 'awscli'
@@ -37,25 +37,24 @@ node['cfe-mariadb']['db_map'].each do |dbx| @@ -37,25 +37,24 @@ node['cfe-mariadb']['db_map'].each do |dbx|
37 end 37 end
38 38
39 filesql = "#{tmp_dir}/#{dbx[:bak_filename]}" 39 filesql = "#{tmp_dir}/#{dbx[:bak_filename]}"
40 - filetgz = "#{filesql}.tar.gz" 40 + filegz = "#{filesql}.gz"
41 41
42 - awscli_s3_file filetgz do 42 + awscli_s3_file filegz do
43 region node['cfe-mariadb']['s3_region'] 43 region node['cfe-mariadb']['s3_region']
44 bucket node['cfe-mariadb']['s3_bucket'] 44 bucket node['cfe-mariadb']['s3_bucket']
45 - key "#{dbx[:bak_filename]}.tar.gz" 45 + key "#{dbx[:bak_filename]}.gz"
46 if manual_creds 46 if manual_creds
47 aws_access_key_id node['cfe-mariadb']['reload']['aws_access_key_id'] 47 aws_access_key_id node['cfe-mariadb']['reload']['aws_access_key_id']
48 aws_secret_access_key node['cfe-mariadb']['reload']['aws_secret_access_key'] 48 aws_secret_access_key node['cfe-mariadb']['reload']['aws_secret_access_key']
49 end 49 end
50 only_if "test -d #{tmp_dir} || mkdir -p #{tmp_dir}" 50 only_if "test -d #{tmp_dir} || mkdir -p #{tmp_dir}"
51 - notifies :run, "execute[untar_#{filetgz}]", :immediately 51 + notifies :run, "execute[unpack_#{filegz}]", :immediately
52 end 52 end
53 53
54 - execute "untar_#{filetgz}" do  
55 - command "tar -xzf #{filetgz} -C #{tmp_dir}/"  
56 - notifies :delete, "file[#{filetgz}]" 54 + execute "unpack_#{filegz}" do
  55 + command "gzip -d #{filegz}"
57 notifies :run, "execute[reload_#{filesql}]", :immediately 56 notifies :run, "execute[reload_#{filesql}]", :immediately
58 - action :nothing 57 + action :nothing
59 end 58 end
60 59
61 execute "reload_#{filesql}" do 60 execute "reload_#{filesql}" do
@@ -67,10 +66,6 @@ node['cfe-mariadb']['db_map'].each do |dbx| @@ -67,10 +66,6 @@ node['cfe-mariadb']['db_map'].each do |dbx|
67 action :nothing 66 action :nothing
68 end 67 end
69 68
70 - file filetgz do  
71 - action :nothing  
72 - end  
73 -  
74 file filesql do 69 file filesql do
75 action :nothing 70 action :nothing
76 end 71 end
  1 +#
  2 +# Author:: Earth U (<sysadmin @ chromedia.com>)
  3 +# Cookbook Name:: cfe-mariadb
  4 +# Recipe:: reload_tar_from_s3
  5 +#
  6 +# Copyright 2016, Chromedia Far East, Inc.
  7 +#
  8 +# Licensed under the Apache License, Version 2.0 (the "License");
  9 +# you may not use this file except in compliance with the License.
  10 +# You may obtain a copy of the License at
  11 +#
  12 +# http://www.apache.org/licenses/LICENSE-2.0
  13 +#
  14 +# Unless required by applicable law or agreed to in writing, software
  15 +# distributed under the License is distributed on an "AS IS" BASIS,
  16 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17 +# See the License for the specific language governing permissions and
  18 +# limitations under the License.
  19 +#
  20 +
  21 +# This recipe is just here for backward-compatibility reasons.
  22 +# The previous backups scripts create .tar.gz files, instead of .gz, so
  23 +# this recipe is here to get .tar.gz backups.
  24 +
  25 +# Download a tarball of a MySQL dump from an S3 bucket,
  26 +# then load it up into a (preferably empty) database.
  27 +
  28 +include_recipe 'awscli'
  29 +
  30 +tmp_dir = ::File.join(Chef::Config[:file_cache_path], 'db_dumps')
  31 +manual_creds = node['cfe-mariadb'].has_key?('reload') &&
  32 + node['cfe-mariadb']['reload'].has_key?('aws_access_key_id')
  33 +
  34 +node['cfe-mariadb']['db_map'].each do |dbx|
  35 +
  36 + if dbx.is_a?(Array)
  37 + dbx_name = dbx[0]
  38 + dbx = dbx[1]
  39 + else
  40 + dbx_name = dbx[:db_name]
  41 + end
  42 +
  43 + filesql = "#{tmp_dir}/#{dbx[:bak_filename]}"
  44 + filetgz = "#{filesql}.tar.gz"
  45 +
  46 + awscli_s3_file filetgz do
  47 + region node['cfe-mariadb']['s3_region']
  48 + bucket node['cfe-mariadb']['s3_bucket']
  49 + key "#{dbx[:bak_filename]}.tar.gz"
  50 + if manual_creds
  51 + aws_access_key_id node['cfe-mariadb']['reload']['aws_access_key_id']
  52 + aws_secret_access_key node['cfe-mariadb']['reload']['aws_secret_access_key']
  53 + end
  54 + only_if "test -d #{tmp_dir} || mkdir -p #{tmp_dir}"
  55 + notifies :run, "execute[untar_#{filetgz}]", :immediately
  56 + end
  57 +
  58 + execute "untar_#{filetgz}" do
  59 + command "tar -xzf #{filetgz} -C #{tmp_dir}/"
  60 + notifies :delete, "file[#{filetgz}]"
  61 + notifies :run, "execute[reload_#{filesql}]", :immediately
  62 + action :nothing
  63 + end
  64 +
  65 + execute "reload_#{filesql}" do
  66 + command "mysql -h #{node['mariadb']['mysqld']['bind_address']} "\
  67 + "-P #{node['mariadb']['mysqld']['port']} -u #{dbx[:db_user]} "\
  68 + "-p'#{dbx[:db_pass]}' -D #{dbx_name} < #{filesql}"
  69 + notifies :delete, "file[#{filesql}]"
  70 + sensitive true
  71 + action :nothing
  72 + end
  73 +
  74 + file filetgz do
  75 + action :nothing
  76 + end
  77 +
  78 + file filesql do
  79 + action :nothing
  80 + end
  81 +end
@@ -6,6 +6,10 @@ @@ -6,6 +6,10 @@
6 6
7 set -e 7 set -e
8 8
  9 +suffix=.backup_db_to_s3
  10 +[ -f /tmp/*"$suffix" ] && exit 200
  11 +tmp_file=$( mktemp --suffix "$suffix" )
  12 +
9 <% bak_dir = "#{Chef::Config[:file_cache_path]}/backup_db_to_s3" -%> 13 <% bak_dir = "#{Chef::Config[:file_cache_path]}/backup_db_to_s3" -%>
10 bak_dir=<%= bak_dir %> 14 bak_dir=<%= bak_dir %>
11 db_host=<%= @db_ip %> 15 db_host=<%= @db_ip %>
@@ -113,4 +117,5 @@ increment_backup_names <%= db[:bak_filename] %> <%= db[:bak_maxcopies] %> @@ -113,4 +117,5 @@ increment_backup_names <%= db[:bak_filename] %> <%= db[:bak_maxcopies] %>
113 upload_to_s3 <%= db[:bak_filename] %> 117 upload_to_s3 <%= db[:bak_filename] %>
114 118
115 <% end -%> 119 <% end -%>
  120 +rm "$tmp_file"
116 echo "$(date) : Done." 121 echo "$(date) : Done."