Add support for PostgreSQL backups

This commit is contained in:
Greg Karékinian 2017-04-07 18:19:55 +02:00
parent d49f28574c
commit 4e5d452aff
3 changed files with 25 additions and 15 deletions

View File

@ -58,6 +58,12 @@ if node["backup"]["default_model"]
end
include_recipe 'logrotate'
if node["backup"]["mysql"]
# Install MySQL client (includes mysqldump)
mysql_client 'default' do
action :create
end
end
logrotate_app 'backup' do
path '/var/log/backup.log'

View File

@ -16,6 +16,10 @@ KosmosBackup.new(:default, 'default backup') do
<%- end -%>
<%- end -%>
<%- if node["backup"]["postgresql"] -%>
database PostgreSQL
<%- end -%>
<%- if node["mongodb"] -%>
<%- node["backup"]["mongodb"]["databases"].each do |db_name| -%>
database MongoDB, :"<%= db_name.to_sym %>" do |db|

View File

@ -45,11 +45,11 @@ Database::MySQL.defaults do |db|
end
<%- end -%>
<%- if node["backup"]["postgresql"] -%>
<%- if node["backup"]["mysql"] -%>
Database::MySQL.defaults do |db|
db.host = "<%= node["backup"]["postgresql"]["host"] %>"
db.username = "<%= node["backup"]["postgresql"]["username"] %>"
db.password = "<%= node["backup"]["postgresql"]["password"] %>"
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 -%>
@ -63,17 +63,17 @@ Database::Redis.defaults do |db|
end
<%- if node["backup"]["postgresql"] -%>
database PostgreSQL do |db|
db.username = ""
db.password = "<%= node['postgresql']['password']['postgres'] %>"
db.host = "localhost"
db.port = 5432
db.socket = "/tmp/pg.sock"
# When dumping all databases, `skip_tables` and `only_tables` are ignored.
db.skip_tables = ['skip', 'these', 'tables']
db.only_tables = ['only', 'these' 'tables']
db.additional_options = []
end
Database::PostgreSQL.defaults do |db|
db.username = "<%= node["backup"]["postgresql"]["username"] %>"
db.password = "<%= node["backup"]["postgresql"]["password"] %>"
db.host = "<%= node["backup"]["postgresql"]["host"] %>"
db.port = 5432
# db.socket = "/var/run/postgresql/.s.PGSQL.5432"
# When dumping all databases, `skip_tables` and `only_tables` are ignored.
db.skip_tables = []
db.only_tables = []
db.additional_options = []
end
<% end -%>
preconfigure 'KosmosBackup' do