Mercurial > repos > other > Puppet
annotate modules/mysql/manifests/backup/xtrabackup.pp @ 454:d0e7979c7e8c
Update PHP configs for Ubuntu
Mostly fixing some INI naming so that it is consistent
between packages and what we write (so we don't end up with
mixed/duplicate content)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 13 Aug 2023 15:26:37 +0100 |
parents | c6c9a2cfcfbd |
children | adf6fe9bbc17 |
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 ( |
443 | 6 Optional[String] $backupuser = undef, |
7 Optional[Variant[String, Sensitive[String]]] $backuppassword = undef, | |
8 String $backupdir = '', | |
9 String[1] $maxallowedpacket = '1M', | |
10 String[1] $backupmethod = 'xtrabackup', | |
11 String[1] $backupdirmode = '0700', | |
12 String[1] $backupdirowner = 'root', | |
13 String[1] $backupdirgroup = $mysql::params::root_group, | |
14 Boolean $backupcompress = true, | |
15 Variant[Integer, String[1]] $backuprotate = 30, | |
16 String[1] $backupscript_template = 'mysql/xtrabackup.sh.erb', | |
17 Optional[String[1]] $backup_success_file_path = undef, | |
18 Boolean $ignore_events = true, | |
19 Boolean $delete_before_dump = false, | |
20 Array[String[1]] $backupdatabases = [], | |
21 Boolean $file_per_database = false, | |
22 Boolean $include_triggers = true, | |
23 Boolean $include_routines = false, | |
24 Enum['present', 'absent'] $ensure = 'present', | |
25 Variant[Array[String[1]], Array[Integer]] $time = ['23', '5'], | |
26 Variant[Boolean, String[1], Array[String[1]]] $prescript = false, | |
27 Variant[Boolean, String[1], Array[String[1]]] $postscript = false, | |
28 String[1] $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', | |
29 Array[String[1]] $optional_args = [], | |
30 String[1] $additional_cron_args = '--backup', | |
31 Boolean $incremental_backups = true, | |
32 Boolean $install_cron = true, | |
33 Optional[String[1]] $compression_command = undef, | |
34 Optional[String[1]] $compression_extension = undef, | |
35 String[1] $backupmethod_package = $mysql::params::xtrabackup_package_name, | |
36 Array[String] $excludedatabases = [], | |
244 | 37 ) inherits mysql::params { |
443 | 38 ensure_packages($backupmethod_package) |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 |
389 | 40 $backuppassword_unsensitive = if $backuppassword =~ Sensitive { |
41 $backuppassword.unwrap | |
42 } else { | |
43 $backuppassword | |
44 } | |
244 | 45 |
46 if $backupuser and $backuppassword { | |
47 mysql_user { "${backupuser}@localhost": | |
48 ensure => $ensure, | |
49 password_hash => mysql::password($backuppassword), | |
50 require => Class['mysql::server::root_password'], | |
51 } | |
443 | 52 # Percona XtraBackup needs additional grants/privileges to work with MySQL 8 |
53 if versioncmp($facts['mysql_version'], '8') >= 0 and !(/(?i:mariadb)/ in $facts['mysqld_version']) { | |
54 if ($facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['major'], '11') >= 0) or | |
55 ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '22.04') >= 0) { | |
56 mysql_grant { "${backupuser}@localhost/*.*": | |
57 ensure => $ensure, | |
58 user => "${backupuser}@localhost", | |
59 table => '*.*', | |
60 privileges => ['BINLOG MONITOR', 'RELOAD', 'PROCESS', 'LOCK TABLES', 'BACKUP_ADMIN'], | |
61 require => Mysql_user["${backupuser}@localhost"], | |
62 } | |
63 } | |
64 else { | |
65 mysql_grant { "${backupuser}@localhost/*.*": | |
66 ensure => $ensure, | |
67 user => "${backupuser}@localhost", | |
68 table => '*.*', | |
69 privileges => ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT', 'BACKUP_ADMIN'], | |
70 require => Mysql_user["${backupuser}@localhost"], | |
71 } | |
72 } | |
73 mysql_grant { "${backupuser}@localhost/performance_schema.keyring_component_status": | |
74 ensure => $ensure, | |
75 user => "${backupuser}@localhost", | |
76 table => 'performance_schema.keyring_component_status', | |
77 privileges => ['SELECT'], | |
78 require => Mysql_user["${backupuser}@localhost"], | |
79 } | |
80 mysql_grant { "${backupuser}@localhost/performance_schema.log_status": | |
81 ensure => $ensure, | |
82 user => "${backupuser}@localhost", | |
83 table => 'performance_schema.log_status', | |
84 privileges => ['SELECT'], | |
85 require => Mysql_user["${backupuser}@localhost"], | |
86 } | |
87 } | |
88 else { | |
89 if $facts['os']['family'] == 'debian' and $facts['os']['release']['major'] == '11' or | |
90 ($facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['major'], '22.04') >= 0) { | |
91 mysql_grant { "${backupuser}@localhost/*.*": | |
92 ensure => $ensure, | |
93 user => "${backupuser}@localhost", | |
94 table => '*.*', | |
95 privileges => ['BINLOG MONITOR', 'RELOAD', 'PROCESS', 'LOCK TABLES'], | |
96 require => Mysql_user["${backupuser}@localhost"], | |
97 } | |
98 } | |
99 else { | |
100 mysql_grant { "${backupuser}@localhost/*.*": | |
101 ensure => $ensure, | |
102 user => "${backupuser}@localhost", | |
103 table => '*.*', | |
104 privileges => ['RELOAD', 'PROCESS', 'LOCK TABLES', 'REPLICATION CLIENT'], | |
105 require => Mysql_user["${backupuser}@localhost"], | |
106 } | |
107 } | |
244 | 108 } |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
109 } |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
110 |
389 | 111 if $install_cron { |
443 | 112 if $facts['os']['family'] == 'RedHat' { |
389 | 113 ensure_packages('cronie') |
443 | 114 } elsif $facts['os']['family'] != 'FreeBSD' { |
389 | 115 ensure_packages('cron') |
116 } | |
117 } | |
118 | |
244 | 119 if $incremental_backups { |
389 | 120 # Warn if old backups are removed too soon. Incremental backups will fail |
121 # if the full backup is no longer available. | |
122 if ($backuprotate.convert_to(Integer) < 7) { | |
123 warning('The value for `backuprotate` is too low, it must be set to at least 7 days when using incremental backups.') | |
124 } | |
125 | |
126 # The --target-dir uses a more predictable value for the full backup so | |
127 # that it can easily be calculated and used in incremental backup jobs. | |
128 # Besides that it allows to have multiple full backups. | |
244 | 129 cron { 'xtrabackup-weekly': |
130 ensure => $ensure, | |
389 | 131 command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir}/$(date +\\%F)_full ${additional_cron_args}", |
244 | 132 user => 'root', |
133 hour => $time[0], | |
134 minute => $time[1], | |
135 weekday => '0', | |
443 | 136 require => Package[$backupmethod_package], |
244 | 137 } |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
138 } |
244 | 139 |
389 | 140 # Wether to use GNU or BSD date format. |
443 | 141 case $facts['os']['family'] { |
389 | 142 'FreeBSD','OpenBSD': { |
143 $dateformat = '$(date -v-sun +\\%F)_full' | |
144 } | |
145 default: { | |
146 $dateformat = '$(date -d "last sunday" +\\%F)_full' | |
147 } | |
148 } | |
149 | |
244 | 150 $daily_cron_data = ($incremental_backups) ? { |
151 true => { | |
389 | 152 'directories' => "--incremental-basedir=${backupdir}/${dateformat} --target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)", |
244 | 153 'weekday' => '1-6', |
154 }, | |
155 false => { | |
389 | 156 'directories' => "--target-dir=${backupdir}/$(date +\\%F_\\%H-\\%M-\\%S)", |
244 | 157 'weekday' => '*', |
158 }, | |
159 } | |
160 | |
161 cron { 'xtrabackup-daily': | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
162 ensure => $ensure, |
244 | 163 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
|
164 user => 'root', |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
165 hour => $time[0], |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
166 minute => $time[1], |
244 | 167 weekday => $daily_cron_data['weekday'], |
443 | 168 require => Package[$backupmethod_package], |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
169 } |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
170 |
244 | 171 file { $backupdir: |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
172 ensure => 'directory', |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
173 mode => $backupdirmode, |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
174 owner => $backupdirowner, |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
175 group => $backupdirgroup, |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
176 } |
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
177 |
389 | 178 # TODO: use EPP instead of ERB, as EPP can handle Data of Type Sensitive without further ado |
244 | 179 file { 'xtrabackup.sh': |
180 ensure => $ensure, | |
181 path => '/usr/local/sbin/xtrabackup.sh', | |
182 mode => '0700', | |
183 owner => 'root', | |
184 group => $mysql::params::root_group, | |
185 content => template($backupscript_template), | |
186 } | |
26
58d1818c2ded
Update MySQL module (which adds "staging" module)
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
187 } |