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:
parent
d59b1a3526
commit
afc25cba89
@ -32,10 +32,26 @@ class subunit2sql::server (
|
|||||||
content => template('subunit2sql/subunit2sql.conf.erb'),
|
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':
|
exec { 'upgrade_subunit2sql_db':
|
||||||
command => 'subunit2sql-db-manage --config-file /etc/subunit2sql.conf upgrade head',
|
command => 'subunit2sql-db-manage --config-file /etc/subunit2sql.conf upgrade head',
|
||||||
path => '/usr/local/bin:/usr/bin:/bin/',
|
path => '/usr/local/bin:/usr/bin:/bin/',
|
||||||
subscribe => Package['subunit2sql'],
|
subscribe => Exec['backup_subunit2sql_db'],
|
||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
templates/subunit2sql-my.cnf.erb
Normal file
5
templates/subunit2sql-my.cnf.erb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[client]
|
||||||
|
host=<%= @db_host %>
|
||||||
|
user=<%= @db_user %>
|
||||||
|
password=<%= @db_pass %>
|
||||||
|
port=<%= @db_port %>
|
Loading…
x
Reference in New Issue
Block a user