From afc25cba892436e1b8242c25afdbef117519247b Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 2 Mar 2015 16:04:40 -0500 Subject: [PATCH] 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 --- manifests/server.pp | 18 +++++++++++++++++- templates/subunit2sql-my.cnf.erb | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 templates/subunit2sql-my.cnf.erb diff --git a/manifests/server.pp b/manifests/server.pp index a825468..857b295 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -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, } } diff --git a/templates/subunit2sql-my.cnf.erb b/templates/subunit2sql-my.cnf.erb new file mode 100644 index 0000000..6638511 --- /dev/null +++ b/templates/subunit2sql-my.cnf.erb @@ -0,0 +1,5 @@ +[client] +host=<%= @db_host %> +user=<%= @db_user %> +password=<%= @db_pass %> +port=<%= @db_port %>