|
1 # See README.me for usage. |
|
2 class mysql::backup::mysqlbackup ( |
|
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 = true, |
|
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 package { 'meb': |
|
31 ensure => $ensure, |
|
32 } |
|
33 |
|
34 # http://dev.mysql.com/doc/mysql-enterprise-backup/3.11/en/mysqlbackup.privileges.html |
|
35 mysql_grant { "${backupuser}@localhost/*.*": |
|
36 ensure => $ensure, |
|
37 user => "${backupuser}@localhost", |
|
38 table => '*.*', |
|
39 privileges => [ 'RELOAD', 'SUPER', 'REPLICATION CLIENT' ], |
|
40 require => Mysql_user["${backupuser}@localhost"], |
|
41 } |
|
42 |
|
43 mysql_grant { "${backupuser}@localhost/mysql.backup_progress": |
|
44 ensure => $ensure, |
|
45 user => "${backupuser}@localhost", |
|
46 table => 'mysql.backup_progress', |
|
47 privileges => [ 'CREATE', 'INSERT', 'DROP', 'UPDATE' ], |
|
48 require => Mysql_user["${backupuser}@localhost"], |
|
49 } |
|
50 |
|
51 mysql_grant { "${backupuser}@localhost/mysql.backup_history": |
|
52 ensure => $ensure, |
|
53 user => "${backupuser}@localhost", |
|
54 table => 'mysql.backup_history', |
|
55 privileges => [ 'CREATE', 'INSERT', 'SELECT', 'DROP', 'UPDATE' ], |
|
56 require => Mysql_user["${backupuser}@localhost"], |
|
57 } |
|
58 |
|
59 cron { 'mysqlbackup-weekly': |
|
60 ensure => $ensure, |
|
61 command => 'mysqlbackup backup', |
|
62 user => 'root', |
|
63 hour => $time[0], |
|
64 minute => $time[1], |
|
65 weekday => 0, |
|
66 require => Package['meb'], |
|
67 } |
|
68 |
|
69 cron { 'mysqlbackup-daily': |
|
70 ensure => $ensure, |
|
71 command => 'mysqlbackup --incremental backup', |
|
72 user => 'root', |
|
73 hour => $time[0], |
|
74 minute => $time[1], |
|
75 weekday => 1-6, |
|
76 require => Package['meb'], |
|
77 } |
|
78 |
|
79 $default_options = { |
|
80 'mysqlbackup' => { |
|
81 'backup-dir' => $backupdir, |
|
82 'with-timestamp' => true, |
|
83 'incremental_base' => 'history:last_backup', |
|
84 'incremental_backup_dir' => $backupdir, |
|
85 'user' => $backupuser, |
|
86 'password' => $backuppassword, |
|
87 } |
|
88 } |
|
89 $options = mysql_deepmerge($default_options, $mysql::server::override_options) |
|
90 |
|
91 file { 'mysqlbackup-config-file': |
|
92 path => '/etc/mysql/conf.d/meb.cnf', |
|
93 content => template('mysql/meb.cnf.erb'), |
|
94 mode => '0600', |
|
95 } |
|
96 |
|
97 file { 'mysqlbackupdir': |
|
98 ensure => 'directory', |
|
99 path => $backupdir, |
|
100 mode => $backupdirmode, |
|
101 owner => $backupdirowner, |
|
102 group => $backupdirgroup, |
|
103 } |
|
104 |
|
105 } |