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