Skip to content

Commit 6ad2fd7

Browse files
committed
Use backup providers
Add MySQL Enterprise Backup and Percona XtraBackup
1 parent 7e81906 commit 6ad2fd7

File tree

4 files changed

+242
-54
lines changed

4 files changed

+242
-54
lines changed

manifests/backup/mysqlbackup.pp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# See README.me for usage.
2+
define mysql::backup::mysqlbackup (
3+
$backupuser,
4+
$backuppassword,
5+
$backupdir,
6+
$backupdirmode = '0700',
7+
$backupdirowner = 'root',
8+
$backupdirgroup = 'root',
9+
$backupcompress = true,
10+
$backuprotate = 30,
11+
$ignore_events = true,
12+
$delete_before_dump = false,
13+
$backupdatabases = [],
14+
$file_per_database = false,
15+
$ensure = 'present',
16+
$time = ['23', '5'],
17+
$postscript = false,
18+
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
19+
) {
20+
21+
mysql_user { "${backupuser}@localhost":
22+
ensure => $ensure,
23+
password_hash => mysql_password($backuppassword),
24+
provider => 'mysql',
25+
require => Class['mysql::server::root_password'],
26+
}
27+
28+
package { 'meb':
29+
ensure => $ensure,
30+
}
31+
32+
# http://dev.mysql.com/doc/mysql-enterprise-backup/3.11/en/mysqlbackup.privileges.html
33+
mysql_grant { "${backupuser}@localhost/*.*":
34+
ensure => $ensure,
35+
user => "${backupuser}@localhost",
36+
table => '*.*',
37+
privileges => [ 'RELOAD', 'SUPER', 'REPLICATION CLIENT' ],
38+
require => Mysql_user["${backupuser}@localhost"],
39+
}
40+
41+
mysql_grant { "${backupuser}@localhost/mysql.backup_progress":
42+
ensure => $ensure,
43+
user => "${backupuser}@localhost",
44+
table => 'mysql.backup_progress',
45+
privileges => [ 'CREATE', 'INSERT', 'DROP', 'UPDATE' ],
46+
require => Mysql_user["${backupuser}@localhost"],
47+
}
48+
49+
mysql_grant { "${backupuser}@localhost/mysql.backup_history":
50+
ensure => $ensure,
51+
user => "${backupuser}@localhost",
52+
table => 'mysql.backup_history',
53+
privileges => [ 'CREATE', 'INSERT', 'SELECT', 'DROP', 'UPDATE' ],
54+
require => Mysql_user["${backupuser}@localhost"],
55+
}
56+
57+
cron { 'mysqlbackup-weekly':
58+
ensure => $ensure,
59+
command => 'mysqlbackup backup',
60+
user => 'root',
61+
hour => $time[0],
62+
minute => $time[1],
63+
weekday => 0,
64+
require => Package['meb'],
65+
}
66+
67+
cron { 'mysqlbackup-daily':
68+
ensure => $ensure,
69+
command => 'mysqlbackup --incremental backup',
70+
user => 'root',
71+
hour => $time[0],
72+
minute => $time[1],
73+
weekday => 1-6,
74+
require => Package['meb'],
75+
}
76+
77+
file { 'mysqlbackupdir':
78+
ensure => 'directory',
79+
path => $backupdir,
80+
mode => $backupdirmode,
81+
owner => $backupdirowner,
82+
group => $backupdirgroup,
83+
}
84+
85+
}

manifests/backup/mysqldump.pp

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# See README.me for usage.
2+
define mysql::backup::mysqldump (
3+
$backupuser,
4+
$backuppassword,
5+
$backupdir,
6+
$backupdirmode = '0700',
7+
$backupdirowner = 'root',
8+
$backupdirgroup = 'root',
9+
$backupcompress = true,
10+
$backuprotate = 30,
11+
$ignore_events = true,
12+
$delete_before_dump = false,
13+
$backupdatabases = [],
14+
$file_per_database = false,
15+
$ensure = 'present',
16+
$time = ['23', '5'],
17+
$postscript = false,
18+
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
19+
) {
20+
21+
mysql_user { "${backupuser}@localhost":
22+
ensure => $ensure,
23+
password_hash => mysql_password($backuppassword),
24+
provider => 'mysql',
25+
require => Class['mysql::server::root_password'],
26+
}
27+
28+
mysql_grant { "${backupuser}@localhost/*.*":
29+
ensure => $ensure,
30+
user => "${backupuser}@localhost",
31+
table => '*.*',
32+
privileges => [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ],
33+
require => Mysql_user["${backupuser}@localhost"],
34+
}
35+
36+
cron { 'mysql-backup':
37+
ensure => $ensure,
38+
command => '/usr/local/sbin/mysqlbackup.sh',
39+
user => 'root',
40+
hour => $time[0],
41+
minute => $time[1],
42+
require => File['mysqlbackup.sh'],
43+
}
44+
45+
file { 'mysqlbackup.sh':
46+
ensure => $ensure,
47+
path => '/usr/local/sbin/mysqlbackup.sh',
48+
mode => '0700',
49+
owner => 'root',
50+
group => 'root',
51+
content => template('mysql/mysqlbackup.sh.erb'),
52+
}
53+
54+
file { 'mysqlbackupdir':
55+
ensure => 'directory',
56+
path => $backupdir,
57+
mode => $backupdirmode,
58+
owner => $backupdirowner,
59+
group => $backupdirgroup,
60+
}
61+
62+
}

manifests/backup/xtrabackup.pp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# See README.me for usage.
2+
define mysql::backup::xtrabackup (
3+
$backupuser,
4+
$backuppassword,
5+
$backupdir,
6+
$backupmethod = 'mysqldump',
7+
$backupdirmode = '0700',
8+
$backupdirowner = 'root',
9+
$backupdirgroup = 'root',
10+
$backupcompress = true,
11+
$backuprotate = 30,
12+
$ignore_events = true,
13+
$delete_before_dump = false,
14+
$backupdatabases = [],
15+
$file_per_database = false,
16+
$ensure = 'present',
17+
$time = ['23', '5'],
18+
$postscript = false,
19+
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
20+
) {
21+
22+
mysql_user { "${backupuser}@localhost":
23+
ensure => $ensure,
24+
password_hash => mysql_password($backuppassword),
25+
provider => 'mysql',
26+
require => Class['mysql::server::root_password'],
27+
}
28+
29+
package{ 'percona-xtrabackup':
30+
ensure => $ensure,
31+
}
32+
cron { 'xtrabackup-weekly':
33+
ensure => $ensure,
34+
command => 'innobackupex $backupdir',
35+
user => 'root',
36+
hour => $time[0],
37+
minute => $time[1],
38+
weekday => 0,
39+
require => Package['percona-xtrabackup'],
40+
}
41+
cron { 'xtrabackup-daily':
42+
ensure => $ensure,
43+
command => 'innobackupex --incremental $backupdir',
44+
user => 'root',
45+
hour => $time[0],
46+
minute => $time[1],
47+
weekday => 1-6,
48+
require => Package['percona-xtrabackup'],
49+
}
50+
51+
file { 'mysqlbackupdir':
52+
ensure => 'directory',
53+
path => $backupdir,
54+
mode => $backupdirmode,
55+
owner => $backupdirowner,
56+
group => $backupdirgroup,
57+
}
58+
59+
}

manifests/server/backup.pp

+36-54
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,43 @@
11
# See README.me for usage.
22
class mysql::server::backup (
3-
$backupuser,
4-
$backuppassword,
5-
$backupdir,
6-
$backupdirmode = '0700',
7-
$backupdirowner = 'root',
8-
$backupdirgroup = 'root',
9-
$backupcompress = true,
10-
$backuprotate = 30,
11-
$ignore_events = true,
3+
$backupuser = undef,
4+
$backuppassword = undef,
5+
$backupdir = undef,
6+
$backupdirmode = '0700',
7+
$backupdirowner = 'root',
8+
$backupdirgroup = 'root',
9+
$backupcompress = true,
10+
$backuprotate = 30,
11+
$ignore_events = true,
1212
$delete_before_dump = false,
13-
$backupdatabases = [],
14-
$file_per_database = false,
15-
$ensure = 'present',
16-
$time = ['23', '5'],
17-
$postscript = false,
18-
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
13+
$backupdatabases = [],
14+
$file_per_database = false,
15+
$ensure = 'present',
16+
$time = ['23', '5'],
17+
$postscript = false,
18+
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
19+
$provider = 'mysqldump',
1920
) {
2021

21-
mysql_user { "${backupuser}@localhost":
22-
ensure => $ensure,
23-
password_hash => mysql_password($backuppassword),
24-
require => Class['mysql::server::root_password'],
25-
}
26-
27-
mysql_grant { "${backupuser}@localhost/*.*":
28-
ensure => $ensure,
29-
user => "${backupuser}@localhost",
30-
table => '*.*',
31-
privileges => [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ],
32-
require => Mysql_user["${backupuser}@localhost"],
33-
}
34-
35-
cron { 'mysql-backup':
36-
ensure => $ensure,
37-
command => '/usr/local/sbin/mysqlbackup.sh',
38-
user => 'root',
39-
hour => $time[0],
40-
minute => $time[1],
41-
require => File['mysqlbackup.sh'],
42-
}
43-
44-
file { 'mysqlbackup.sh':
45-
ensure => $ensure,
46-
path => '/usr/local/sbin/mysqlbackup.sh',
47-
mode => '0700',
48-
owner => 'root',
49-
group => 'root',
50-
content => template('mysql/mysqlbackup.sh.erb'),
51-
}
52-
53-
file { 'mysqlbackupdir':
54-
ensure => 'directory',
55-
path => $backupdir,
56-
mode => $backupdirmode,
57-
owner => $backupdirowner,
58-
group => $backupdirgroup,
59-
}
22+
create_resources("mysql::backup::${provider}", {
23+
"ensure backup is ${ensure} with ${provider}" => {
24+
'backupuser' => $backupuser,
25+
'backuppassword' => $backuppassword,
26+
'backupdir' => $backupdir,
27+
'backupdirmode' => $backupdirmode,
28+
'backupdirowner' => $backupdirowner,
29+
'backupdirgroup' => $backupdirgroup,
30+
'backupcompress' => $backupcompress,
31+
'backuprotate' => $backuprotate,
32+
'ignore_events' => $ignore_events,
33+
'delete_before_dump' => $delete_before_dump,
34+
'backupdatabases' => $backupdatabases,
35+
'file_per_database' => $file_per_database,
36+
'ensure' => $ensure,
37+
'time' => $time,
38+
'postscript' => $postscript,
39+
'execpath' => $execpath,
40+
}
41+
})
6042

6143
}

0 commit comments

Comments
 (0)