forked from puppetlabs/puppetlabs-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqldump.pp
79 lines (72 loc) · 2.13 KB
/
mysqldump.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
# @summary
# "Provider" for mysqldump
# @api private
#
class mysql::backup::mysqldump (
$backupuser = '',
$backuppassword = '',
$backupdir = '',
$maxallowedpacket = '1M',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = 'mysqldump',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_triggers = false,
$include_routines = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
) inherits mysql::params {
if $backupcompress {
ensure_packages(['bzip2'])
Package['bzip2'] -> File['mysqlbackup.sh']
}
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql::password($backuppassword),
require => Class['mysql::server::root_password'],
}
if $include_triggers {
$privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER' ]
} else {
$privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ]
}
mysql_grant { "${backupuser}@localhost/*.*":
ensure => $ensure,
user => "${backupuser}@localhost",
table => '*.*',
privileges => $privs,
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 => $mysql::params::root_group,
content => template('mysql/mysqlbackup.sh.erb'),
}
file { $backupdir:
ensure => 'directory',
mode => $backupdirmode,
owner => $backupdirowner,
group => $backupdirgroup,
}
}