forked from puppetlabs/puppetlabs-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqlbackup.pp
112 lines (101 loc) · 3.19 KB
/
mysqlbackup.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# @summary
# Manage the mysqlbackup client.
#
# @api private
#
class mysql::backup::mysqlbackup (
$backupuser = '',
$backuppassword = '',
$maxallowedpacket = '1M',
$backupdir = '',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = '',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_triggers = true,
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
) inherits mysql::params {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql::password($backuppassword),
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 = $default_options.deep_merge($mysql::server::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,
}
}