Mercurial > repos > other > Puppet
annotate modules/mysql/manifests/backup/xtrabackup.pp @ 244:48d3a1948e4d
Update MySQL module
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Dec 2019 14:11:43 -0500 |
parents | 58d1818c2ded |
children | 668df4711671 |
rev | line source |
---|---|
244 | 1 # @summary |
2 # "Provider" for Percona XtraBackup/MariaBackup | |
3 # @api private | |
4 # | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 class mysql::backup::xtrabackup ( |
244 | 6 $xtrabackup_package_name = $mysql::params::xtrabackup_package_name, |
7 $backupuser = undef, | |
8 $backuppassword = undef, | |
9 $backupdir = '', | |
10 $maxallowedpacket = '1M', | |
11 $backupmethod = 'xtrabackup', | |
12 $backupdirmode = '0700', | |
13 $backupdirowner = 'root', | |
14 $backupdirgroup = $mysql::params::root_group, | |
15 $backupcompress = true, | |
16 $backuprotate = 30, | |
17 $backupscript_template = 'mysql/xtrabackup.sh.erb', | |
18 $backup_success_file_path = undef, | |
19 $ignore_events = true, | |
20 $delete_before_dump = false, | |
21 $backupdatabases = [], | |
22 $file_per_database = false, | |
23 $include_triggers = true, | |
24 $include_routines = false, | |
25 $ensure = 'present', | |
26 $time = ['23', '5'], | |
27 $prescript = false, | |
28 $postscript = false, | |
29 $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', | |
30 $optional_args = [], | |
31 $additional_cron_args = '--backup', | |
32 $incremental_backups = true | |
33 ) inherits mysql::params { | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 |
244 | 35 ensure_packages($xtrabackup_package_name) |
36 | |
37 if $backupuser and $backuppassword { | |
38 mysql_user { "${backupuser}@localhost": | |
39 ensure => $ensure, | |
40 password_hash => mysql::password($backuppassword), | |
41 require => Class['mysql::server::root_password'], | |
42 } | |
43 | |
44 mysql_grant { "${backupuser}@localhost/*.*": | |
45 ensure => $ensure, | |
46 user => "${backupuser}@localhost", | |
47 table => '*.*', | |
48 privileges => [ 'RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT' ], | |
49 require => Mysql_user["${backupuser}@localhost"], | |
50 } | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 } |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 |
244 | 53 if $incremental_backups { |
54 cron { 'xtrabackup-weekly': | |
55 ensure => $ensure, | |
56 command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}", | |
57 user => 'root', | |
58 hour => $time[0], | |
59 minute => $time[1], | |
60 weekday => '0', | |
61 require => Package[$xtrabackup_package_name], | |
62 } | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 } |
244 | 64 |
65 $daily_cron_data = ($incremental_backups) ? { | |
66 true => { | |
67 'directories' => "--incremental-basedir=${backupdir} --target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)", | |
68 'weekday' => '1-6', | |
69 }, | |
70 false => { | |
71 'directories' => "--target-dir=${backupdir}", | |
72 'weekday' => '*', | |
73 }, | |
74 } | |
75 | |
76 cron { 'xtrabackup-daily': | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 ensure => $ensure, |
244 | 78 command => "/usr/local/sbin/xtrabackup.sh ${daily_cron_data['directories']} ${additional_cron_args}", |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 user => 'root', |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 hour => $time[0], |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 minute => $time[1], |
244 | 82 weekday => $daily_cron_data['weekday'], |
83 require => Package[$xtrabackup_package_name], | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 } |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 |
244 | 86 file { $backupdir: |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 ensure => 'directory', |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
88 mode => $backupdirmode, |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 owner => $backupdirowner, |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 group => $backupdirgroup, |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 } |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 |
244 | 93 file { 'xtrabackup.sh': |
94 ensure => $ensure, | |
95 path => '/usr/local/sbin/xtrabackup.sh', | |
96 mode => '0700', | |
97 owner => 'root', | |
98 group => $mysql::params::root_group, | |
99 content => template($backupscript_template), | |
100 } | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 } |