Allow to pass extra attributes to backup PostgreSQL databases

This commit is contained in:
Greg 2019-05-14 16:39:21 +02:00
parent c9547582b7
commit d398c167ca
4 changed files with 26 additions and 20 deletions

View File

@ -27,7 +27,8 @@ default["backup"]["mysql"]["username"] = "root"
default["backup"]["mysql"]["host"] = "localhost"
# PostgreSQL default settings
default["backup"]["postgresql"]["databases"] = []
default["backup"]["postgresql"]["databases"] = {}
default["backup"]["postgresql"]["username"] = "postgres"
default["backup"]["postgresql"]["host"] = "localhost"
default["backup"]["postgresql"]["port"] = 5432

View File

@ -17,9 +17,14 @@ KosmosBackup.new(:default, 'default backup') do
<%- end -%>
<%- if node["backup"]["postgresql"] -%>
<%- node["backup"]["postgresql"]["databases"].each do |db_name| -%>
database PostgreSQL, :"<%= db_name.to_sym %>" do |db|
<%- node["backup"]["postgresql"]["databases"].each do |db_name, h| -%>
database PostgreSQL, :"<%= db_name %>" do |db|
db.name = "<%= db_name %>"
<%- unless h.nil? -%>
<%- h.each do |k, v| -%>
db.<%= k %> = "<%= v %>"
<%- end -%>
<%- end -%>
end
<%- end -%>
<%- end -%>

View File

@ -24,16 +24,22 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
postgresql_data_bag_item = data_bag_item('credentials', 'postgresql')
unless node.chef_environment == "development"
# backup the data dir and the config files
node.override["backup"]["archives"]["ejabberd"] = ["/opt/ejabberd", "/var/www/xmpp.kosmos.org", "/var/www/xmpp.5apps.com"]
unless node["backup"]["postgresql"]["databases"].include? "ejabberd"
node.override["backup"]["postgresql"]["databases"] =
node["backup"]["postgresql"]["databases"].to_a << "ejabberd"
unless node["backup"]["postgresql"]["databases"].keys.include? "ejabberd"
node.override["backup"]["postgresql"]["databases"]["ejabberd"] = {
username: "ejabberd",
password: postgresql_data_bag_item['ejabberd_user_password']
}
end
unless node["backup"]["postgresql"]["databases"].include? "ejabberd_5apps"
node.override["backup"]["postgresql"]["databases"] =
node["backup"]["postgresql"]["databases"].to_a << "ejabberd_5apps"
unless node["backup"]["postgresql"]["databases"].keys.include? "ejabberd_5apps"
node.override["backup"]["postgresql"]["databases"]["ejabberd_5apps"] = {
username: "ejabberd",
password: postgresql_data_bag_item['ejabberd_user_password']
}
end
include_recipe "backup"
end

View File

@ -209,17 +209,11 @@ end
#
unless node.chef_environment == "development"
node.override["backup"]["postgresql"]["host"] = "localhost"
unless platform?('ubuntu') && node[:platform_version].to_f < 18.04
node.override["backup"]["postgresql"]["username"] = "mastodon"
node.override["backup"]["postgresql"]["password"] = postgresql_data_bag_item['mastodon_user_password']
else
node.override["backup"]["postgresql"]["username"] = "postgres"
node.override["backup"]["postgresql"]["password"] = node['postgresql']['password']['postgres']
end
unless node["backup"]["postgresql"]["databases"].include? 'mastodon'
node.override["backup"]["postgresql"]["databases"] =
node["backup"]["postgresql"]["databases"].to_a << "mastodon"
unless node["backup"]["postgresql"]["databases"].keys.include? 'mastodon'
node.override["backup"]["postgresql"]["databases"]["mastodon"] = {
username: "mastodon",
password: postgresql_data_bag_item['mastodon_user_password']
}
end
include_recipe "backup"