comparison 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
comparison
equal deleted inserted replaced
243:aad92dbc0efc 244:48d3a1948e4d
1 # See README.me for usage. 1 # @summary
2 # "Provider" for Percona XtraBackup/MariaBackup
3 # @api private
4 #
2 class mysql::backup::xtrabackup ( 5 class mysql::backup::xtrabackup (
3 $backupuser, 6 $xtrabackup_package_name = $mysql::params::xtrabackup_package_name,
4 $backuppassword, 7 $backupuser = undef,
5 $backupdir, 8 $backuppassword = undef,
6 $backupmethod = 'mysqldump', 9 $backupdir = '',
7 $backupdirmode = '0700', 10 $maxallowedpacket = '1M',
8 $backupdirowner = 'root', 11 $backupmethod = 'xtrabackup',
9 $backupdirgroup = 'root', 12 $backupdirmode = '0700',
10 $backupcompress = true, 13 $backupdirowner = 'root',
11 $backuprotate = 30, 14 $backupdirgroup = $mysql::params::root_group,
12 $ignore_events = true, 15 $backupcompress = true,
13 $delete_before_dump = false, 16 $backuprotate = 30,
14 $backupdatabases = [], 17 $backupscript_template = 'mysql/xtrabackup.sh.erb',
15 $file_per_database = false, 18 $backup_success_file_path = undef,
16 $ensure = 'present', 19 $ignore_events = true,
17 $time = ['23', '5'], 20 $delete_before_dump = false,
18 $postscript = false, 21 $backupdatabases = [],
19 $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', 22 $file_per_database = false,
20 ) { 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 {
21 34
22 mysql_user { "${backupuser}@localhost": 35 ensure_packages($xtrabackup_package_name)
23 ensure => $ensure, 36
24 password_hash => mysql_password($backuppassword), 37 if $backupuser and $backuppassword {
25 provider => 'mysql', 38 mysql_user { "${backupuser}@localhost":
26 require => Class['mysql::server::root_password'], 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 }
27 } 51 }
28 52
29 package{ 'percona-xtrabackup': 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 }
63 }
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':
30 ensure => $ensure, 77 ensure => $ensure,
31 } 78 command => "/usr/local/sbin/xtrabackup.sh ${daily_cron_data['directories']} ${additional_cron_args}",
32 cron { 'xtrabackup-weekly':
33 ensure => $ensure,
34 command => 'innobackupex $backupdir',
35 user => 'root', 79 user => 'root',
36 hour => $time[0], 80 hour => $time[0],
37 minute => $time[1], 81 minute => $time[1],
38 weekday => 0, 82 weekday => $daily_cron_data['weekday'],
39 require => Package['percona-xtrabackup'], 83 require => Package[$xtrabackup_package_name],
40 }
41 cron { 'xtrabackup-daily':
42 ensure => $ensure,
43 command => 'innobackupex --incremental $backupdir',
44 user => 'root',
45 hour => $time[0],
46 minute => $time[1],
47 weekday => 1-6,
48 require => Package['percona-xtrabackup'],
49 } 84 }
50 85
51 file { 'mysqlbackupdir': 86 file { $backupdir:
52 ensure => 'directory', 87 ensure => 'directory',
53 path => $backupdir,
54 mode => $backupdirmode, 88 mode => $backupdirmode,
55 owner => $backupdirowner, 89 owner => $backupdirowner,
56 group => $backupdirgroup, 90 group => $backupdirgroup,
57 } 91 }
58 92
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 }
59 } 101 }