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 end
include_recipe 'logrotate' include_recipe 'logrotate'
if node["backup"]["mysql"]
# Install MySQL client (includes mysqldump)
mysql_client 'default' do
action :create
end
end
logrotate_app 'backup' do logrotate_app 'backup' do
path '/var/log/backup.log' path '/var/log/backup.log'

View File

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

View File

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