Use backup providers
Add MySQL Enterprise Backup and Percona XtraBackup
This commit is contained in:
parent
7e81906e20
commit
58508b772a
6 changed files with 306 additions and 54 deletions
28
README.md
28
README.md
|
@ -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.
|
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::server::monitor
|
||||||
|
|
||||||
#####`mysql_monitor_username`
|
#####`mysql_monitor_username`
|
||||||
|
|
103
manifests/backup/mysqlbackup.pp
Normal file
103
manifests/backup/mysqlbackup.pp
Normal 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
62
manifests/backup/mysqldump.pp
Normal file
62
manifests/backup/mysqldump.pp
Normal 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
manifests/backup/xtrabackup.pp
Normal file
59
manifests/backup/xtrabackup.pp
Normal 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,61 +1,43 @@
|
||||||
# See README.me for usage.
|
# See README.me for usage.
|
||||||
class mysql::server::backup (
|
class mysql::server::backup (
|
||||||
$backupuser,
|
$backupuser = undef,
|
||||||
$backuppassword,
|
$backuppassword = undef,
|
||||||
$backupdir,
|
$backupdir = undef,
|
||||||
$backupdirmode = '0700',
|
$backupdirmode = '0700',
|
||||||
$backupdirowner = 'root',
|
$backupdirowner = 'root',
|
||||||
$backupdirgroup = 'root',
|
$backupdirgroup = 'root',
|
||||||
$backupcompress = true,
|
$backupcompress = true,
|
||||||
$backuprotate = 30,
|
$backuprotate = 30,
|
||||||
$ignore_events = true,
|
$ignore_events = true,
|
||||||
$delete_before_dump = false,
|
$delete_before_dump = false,
|
||||||
$backupdatabases = [],
|
$backupdatabases = [],
|
||||||
$file_per_database = false,
|
$file_per_database = false,
|
||||||
$ensure = 'present',
|
$ensure = 'present',
|
||||||
$time = ['23', '5'],
|
$time = ['23', '5'],
|
||||||
$postscript = false,
|
$postscript = false,
|
||||||
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
|
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
|
||||||
|
$provider = 'mysqldump',
|
||||||
) {
|
) {
|
||||||
|
|
||||||
mysql_user { "${backupuser}@localhost":
|
create_resources("class", {
|
||||||
ensure => $ensure,
|
"mysql::backup::${provider}" => {
|
||||||
password_hash => mysql_password($backuppassword),
|
'backupuser' => $backupuser,
|
||||||
require => Class['mysql::server::root_password'],
|
'backuppassword' => $backuppassword,
|
||||||
}
|
'backupdir' => $backupdir,
|
||||||
|
'backupdirmode' => $backupdirmode,
|
||||||
mysql_grant { "${backupuser}@localhost/*.*":
|
'backupdirowner' => $backupdirowner,
|
||||||
ensure => $ensure,
|
'backupdirgroup' => $backupdirgroup,
|
||||||
user => "${backupuser}@localhost",
|
'backupcompress' => $backupcompress,
|
||||||
table => '*.*',
|
'backuprotate' => $backuprotate,
|
||||||
privileges => [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ],
|
'ignore_events' => $ignore_events,
|
||||||
require => Mysql_user["${backupuser}@localhost"],
|
'delete_before_dump' => $delete_before_dump,
|
||||||
}
|
'backupdatabases' => $backupdatabases,
|
||||||
|
'file_per_database' => $file_per_database,
|
||||||
cron { 'mysql-backup':
|
'ensure' => $ensure,
|
||||||
ensure => $ensure,
|
'time' => $time,
|
||||||
command => '/usr/local/sbin/mysqlbackup.sh',
|
'postscript' => $postscript,
|
||||||
user => 'root',
|
'execpath' => $execpath,
|
||||||
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,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
18
templates/meb.cnf.erb
Normal file
18
templates/meb.cnf.erb
Normal 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 -%>
|
Loading…
Reference in a new issue