Add backup before running db migrations

Previously on new subunit2sql releases we would automatically run the
db upgrade command to cover any potential db migrations added in the
new release. However if there is a potential issue with a new migration
this could potentially corrupt the db. So to offset this risk this
commit runs a mysqldump to backup the db before we run the migration
command so in case things go bad we can restore the db from the backup.

Change-Id: I65d300699c457aeb4ead86c08077f7495eb24ed4
This commit is contained in:
Matthew Treinish 2015-03-02 16:04:40 -05:00
parent d59b1a3526
commit afc25cba89
2 changed files with 22 additions and 1 deletions

View File

@ -32,10 +32,26 @@ class subunit2sql::server (
content => template('subunit2sql/subunit2sql.conf.erb'),
}
file {'/etc/subunit2sql-my.cnf':
ensure => present,
owner => 'root',
group => 'root',
mode => '0400',
content => template('subunit2sql/subunit2sql-my.cnf.erb'),
}
exec { 'backup_subunit2sql_db':
command => 'mysqldump --defaults-file=/etc/subunit2sql-my.cnf --opt $db_name | gzip -9 > /opt/subunit2sql.sql.gz',
path => '/usr/local/bin:/usr/bin:/bin/',
subscribe => Package['subunit2sql'],
require => File['/etc/subunit2sql-my.cnf'],
refreshonly => true,
}
exec { 'upgrade_subunit2sql_db':
command => 'subunit2sql-db-manage --config-file /etc/subunit2sql.conf upgrade head',
path => '/usr/local/bin:/usr/bin:/bin/',
subscribe => Package['subunit2sql'],
subscribe => Exec['backup_subunit2sql_db'],
refreshonly => true,
}
}

View File

@ -0,0 +1,5 @@
[client]
host=<%= @db_host %>
user=<%= @db_user %>
password=<%= @db_pass %>
port=<%= @db_port %>