From ffc6858dcc69b507d58451a0c8eda84eed14baf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 9 Nov 2018 14:01:33 +0100 Subject: [PATCH] Do not pass the password on the command line anymore to fix a warning Since email notifications work now we do not want warnings. Write an option file with the credentials for mysqldump (https://dev.mysql.com/doc/refman/5.7/en/option-files.html) --- site-cookbooks/backup/recipes/default.rb | 32 +++++++++++-------- .../backup/templates/default/config.rb.erb | 1 - 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/site-cookbooks/backup/recipes/default.rb b/site-cookbooks/backup/recipes/default.rb index b69c344..8d34348 100644 --- a/site-cookbooks/backup/recipes/default.rb +++ b/site-cookbooks/backup/recipes/default.rb @@ -63,18 +63,22 @@ mysql_client 'default' do not_if { node["backup"]["mysql"]["databases"].empty? } end - include_recipe 'logrotate' - unless node["backup"]["mysql"]["databases"].empty? - # Install MySQL client (includes mysqldump) - mysql_client 'default' do - action :create - end - end - - logrotate_app 'backup' do - path '/var/log/backup.log' - frequency 'daily' - rotate 10 - create '640 root root' - end +# Write the credentials file to allow dumps without password for the root +# user (https://dev.mysql.com/doc/refman/5.7/en/option-files.html) +file "/root/.my.cnf" do + mode "600" + content lazy { <<-EOF +[client] +user=#{node["backup"]["mysql"]["username"]} +password=#{node["backup"]["mysql"]["password"]} + EOF + } + not_if { node["backup"]["mysql"]["password"].nil? } +end + +logrotate_app 'backup' do + path '/var/log/backup.log' + frequency 'daily' + rotate 10 + create '640 root root' end diff --git a/site-cookbooks/backup/templates/default/config.rb.erb b/site-cookbooks/backup/templates/default/config.rb.erb index 2e10774..dec61a8 100644 --- a/site-cookbooks/backup/templates/default/config.rb.erb +++ b/site-cookbooks/backup/templates/default/config.rb.erb @@ -40,7 +40,6 @@ end Database::MySQL.defaults do |db| db.host = "<%= node["backup"]["mysql"]["host"] %>" db.username = "<%= node["backup"]["mysql"]["username"] %>" - db.password = "<%= node["backup"]["mysql"]["password"] %>" db.additional_options = ['--quick', '--single-transaction'] end <%- end -%>