Skip to content

Use backup providers #649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
103 changes: 103 additions & 0 deletions manifests/backup/mysqlbackup.pp
Original file line number Diff line number Diff line change
@@ -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 changes: 62 additions & 0 deletions manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
@@ -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 changes: 59 additions & 0 deletions manifests/backup/xtrabackup.pp
Original file line number Diff line number Diff line change
@@ -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,
}

}
90 changes: 36 additions & 54 deletions manifests/server/backup.pp
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions templates/meb.cnf.erb
Original file line number Diff line number Diff line change
@@ -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 -%>