Use backup providers

Add MySQL Enterprise Backup and Percona XtraBackup
This commit is contained in:
Daniël van Eeden 2015-01-27 22:08:37 +01:00
parent 7e81906e20
commit 58508b772a
6 changed files with 306 additions and 54 deletions

View file

@ -353,6 +353,34 @@ An array of two elements to set the backup time. Allows ['23', '5'] or ['3', '4
A script that is executed at when the backup is finished. This could be used to (r)sync the backup to a central store. This script can be either a single line that is directly executed or a number of lines, when supplied as an array. It could also be one or more externally managed (executable) files.
#####`provider`
Set backup implementation
* `mysqldump`
* `mysqlbackup`: MySQL Enterprise Backup
* `xtrabackup`: Percona XtraBackup
####mysql::backup::mysqldump
Implements mysql::server::backup with mysqldump
Backup type: Logical
####mysql::backup::mysqlbackup
Implements mysql::server::backup with MySQL Enterprise Backup from Oracle
Backup type: Physical
For this you need the meb package, which is available in RPM and TAR format from Oracle. For Ubuntu you can use [meb-deb](https://github.com/dveeden/meb-deb) to create a package from an official tarball.
####mysql::backup::xtrabackup
Implements mysql::server::backup with XtraBackup from Percona
Backup type: Physical
####mysql::server::monitor
#####`mysql_monitor_username`

View file

@ -0,0 +1,103 @@
# See README.me for usage.
class mysql::backup::mysqlbackup (
$backupuser,
$backuppassword,
$backupdir,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$ensure = 'present',
$time = ['23', '5'],
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql_password($backuppassword),
provider => 'mysql',
require => Class['mysql::server::root_password'],
}
package { 'meb':
ensure => $ensure,
}
# http://dev.mysql.com/doc/mysql-enterprise-backup/3.11/en/mysqlbackup.privileges.html
mysql_grant { "${backupuser}@localhost/*.*":
ensure => $ensure,
user => "${backupuser}@localhost",
table => '*.*',
privileges => [ 'RELOAD', 'SUPER', 'REPLICATION CLIENT' ],
require => Mysql_user["${backupuser}@localhost"],
}
mysql_grant { "${backupuser}@localhost/mysql.backup_progress":
ensure => $ensure,
user => "${backupuser}@localhost",
table => 'mysql.backup_progress',
privileges => [ 'CREATE', 'INSERT', 'DROP', 'UPDATE' ],
require => Mysql_user["${backupuser}@localhost"],
}
mysql_grant { "${backupuser}@localhost/mysql.backup_history":
ensure => $ensure,
user => "${backupuser}@localhost",
table => 'mysql.backup_history',
privileges => [ 'CREATE', 'INSERT', 'SELECT', 'DROP', 'UPDATE' ],
require => Mysql_user["${backupuser}@localhost"],
}
cron { 'mysqlbackup-weekly':
ensure => $ensure,
command => 'mysqlbackup backup',
user => 'root',
hour => $time[0],
minute => $time[1],
weekday => 0,
require => Package['meb'],
}
cron { 'mysqlbackup-daily':
ensure => $ensure,
command => 'mysqlbackup --incremental backup',
user => 'root',
hour => $time[0],
minute => $time[1],
weekday => 1-6,
require => Package['meb'],
}
$default_options = {
'mysqlbackup' => {
'backup-dir' => $backupdir,
'with-timestamp' => true,
'incremental_base' => 'history:last_backup',
'incremental_backup_dir' => $backupdir,
'user' => $backupuser,
'password' => $backuppassword,
}
}
$options = mysql_deepmerge($default_options, $override_options)
file { 'mysqlbackup-config-file':
path => '/etc/mysql/conf.d/meb.cnf',
content => template('mysql/meb.cnf.erb'),
mode => '0600',
}
file { 'mysqlbackupdir':
ensure => 'directory',
path => $backupdir,
mode => $backupdirmode,
owner => $backupdirowner,
group => $backupdirgroup,
}
}

View file

@ -0,0 +1,62 @@
# See README.me for usage.
class mysql::backup::mysqldump (
$backupuser,
$backuppassword,
$backupdir,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$ensure = 'present',
$time = ['23', '5'],
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql_password($backuppassword),
provider => 'mysql',
require => Class['mysql::server::root_password'],
}
mysql_grant { "${backupuser}@localhost/*.*":
ensure => $ensure,
user => "${backupuser}@localhost",
table => '*.*',
privileges => [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ],
require => Mysql_user["${backupuser}@localhost"],
}
cron { 'mysql-backup':
ensure => $ensure,
command => '/usr/local/sbin/mysqlbackup.sh',
user => 'root',
hour => $time[0],
minute => $time[1],
require => File['mysqlbackup.sh'],
}
file { 'mysqlbackup.sh':
ensure => $ensure,
path => '/usr/local/sbin/mysqlbackup.sh',
mode => '0700',
owner => 'root',
group => 'root',
content => template('mysql/mysqlbackup.sh.erb'),
}
file { 'mysqlbackupdir':
ensure => 'directory',
path => $backupdir,
mode => $backupdirmode,
owner => $backupdirowner,
group => $backupdirgroup,
}
}

View file

@ -0,0 +1,59 @@
# See README.me for usage.
class mysql::backup::xtrabackup (
$backupuser,
$backuppassword,
$backupdir,
$backupmethod = 'mysqldump',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$ensure = 'present',
$time = ['23', '5'],
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
) {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql_password($backuppassword),
provider => 'mysql',
require => Class['mysql::server::root_password'],
}
package{ 'percona-xtrabackup':
ensure => $ensure,
}
cron { 'xtrabackup-weekly':
ensure => $ensure,
command => 'innobackupex $backupdir',
user => 'root',
hour => $time[0],
minute => $time[1],
weekday => 0,
require => Package['percona-xtrabackup'],
}
cron { 'xtrabackup-daily':
ensure => $ensure,
command => 'innobackupex --incremental $backupdir',
user => 'root',
hour => $time[0],
minute => $time[1],
weekday => 1-6,
require => Package['percona-xtrabackup'],
}
file { 'mysqlbackupdir':
ensure => 'directory',
path => $backupdir,
mode => $backupdirmode,
owner => $backupdirowner,
group => $backupdirgroup,
}
}

View file

@ -1,61 +1,43 @@
# See README.me for usage.
class mysql::server::backup (
$backupuser,
$backuppassword,
$backupdir,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$ignore_events = true,
$backupuser = undef,
$backuppassword = undef,
$backupdir = undef,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$ensure = 'present',
$time = ['23', '5'],
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$backupdatabases = [],
$file_per_database = false,
$ensure = 'present',
$time = ['23', '5'],
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$provider = 'mysqldump',
) {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql_password($backuppassword),
require => Class['mysql::server::root_password'],
}
mysql_grant { "${backupuser}@localhost/*.*":
ensure => $ensure,
user => "${backupuser}@localhost",
table => '*.*',
privileges => [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ],
require => Mysql_user["${backupuser}@localhost"],
}
cron { 'mysql-backup':
ensure => $ensure,
command => '/usr/local/sbin/mysqlbackup.sh',
user => 'root',
hour => $time[0],
minute => $time[1],
require => File['mysqlbackup.sh'],
}
file { 'mysqlbackup.sh':
ensure => $ensure,
path => '/usr/local/sbin/mysqlbackup.sh',
mode => '0700',
owner => 'root',
group => 'root',
content => template('mysql/mysqlbackup.sh.erb'),
}
file { 'mysqlbackupdir':
ensure => 'directory',
path => $backupdir,
mode => $backupdirmode,
owner => $backupdirowner,
group => $backupdirgroup,
}
create_resources("class", {
"mysql::backup::${provider}" => {
'backupuser' => $backupuser,
'backuppassword' => $backuppassword,
'backupdir' => $backupdir,
'backupdirmode' => $backupdirmode,
'backupdirowner' => $backupdirowner,
'backupdirgroup' => $backupdirgroup,
'backupcompress' => $backupcompress,
'backuprotate' => $backuprotate,
'ignore_events' => $ignore_events,
'delete_before_dump' => $delete_before_dump,
'backupdatabases' => $backupdatabases,
'file_per_database' => $file_per_database,
'ensure' => $ensure,
'time' => $time,
'postscript' => $postscript,
'execpath' => $execpath,
}
})
}

18
templates/meb.cnf.erb Normal file
View file

@ -0,0 +1,18 @@
### MANAGED BY PUPPET ###
<% @options.sort.map do |k,v| -%>
<% if v.is_a?(Hash) -%>
[<%= k %>]
<% v.sort.map do |ki, vi| -%>
<% if vi == true or v == '' -%>
<%= ki %>
<% elsif vi.is_a?(Array) -%>
<% vi.each do |vii| -%>
<%= ki %> = <%= vii %>
<% end -%>
<% elsif ![nil, '', :undef].include?(vi) -%>
<%= ki %> = <%= vi %>
<% end -%>
<% end -%>
<% end %>
<% end -%>