Skip to content

Commit ada0345

Browse files
author
deepak
committed
Allow to set and run backups using another user via cron , default is set as root via params if no cronbackupuser is specified.
1 parent 8c5ba7b commit ada0345

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

Diff for: manifests/backup/mysqlbackup.pp

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class mysql::backup::mysqlbackup (
77
$backupuser = '',
88
Variant[String, Sensitive[String]] $backuppassword = '',
9+
$backupcronuser = $mysql::params::backupcronuser,
910
$maxallowedpacket = '1M',
1011
$backupdir = '',
1112
$backupdirmode = '0700',
@@ -84,7 +85,7 @@
8485
cron { 'mysqlbackup-weekly':
8586
ensure => $ensure,
8687
command => 'mysqlbackup backup',
87-
user => 'root',
88+
user => $backupcronuser,
8889
hour => $time[0],
8990
minute => $time[1],
9091
weekday => '0',
@@ -94,7 +95,7 @@
9495
cron { 'mysqlbackup-daily':
9596
ensure => $ensure,
9697
command => 'mysqlbackup --incremental backup',
97-
user => 'root',
98+
user => $backupcronuser,
9899
hour => $time[0],
99100
minute => $time[1],
100101
weekday => '1-6',

Diff for: manifests/backup/mysqldump.pp

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
class mysql::backup::mysqldump (
66
$backupuser = '',
7+
$backupcronuser = $mysql::params::backupcronuser,
78
Variant[String, Sensitive[String]] $backuppassword = '',
89
$backupdir = '',
910
$maxallowedpacket = '1M',
@@ -79,7 +80,7 @@
7980
cron { 'mysql-backup':
8081
ensure => $ensure,
8182
command => '/usr/local/sbin/mysqlbackup.sh',
82-
user => 'root',
83+
user => $backupcronuser,
8384
hour => $time[0],
8485
minute => $time[1],
8586
monthday => $time[2],
@@ -93,7 +94,7 @@
9394
ensure => $ensure,
9495
path => '/usr/local/sbin/mysqlbackup.sh',
9596
mode => '0700',
96-
owner => 'root',
97+
owner => $backupcronuser,
9798
group => $mysql::params::root_group,
9899
content => template('mysql/mysqlbackup.sh.erb'),
99100
}

Diff for: manifests/backup/xtrabackup.pp

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class mysql::backup::xtrabackup (
66
$backupuser = undef,
77
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
8+
$backupcronuser = $mysql::params::backupcronuser,
89
$backupdir = '',
910
$maxallowedpacket = '1M',
1011
$backupmethod = 'xtrabackup',
@@ -129,7 +130,7 @@
129130
cron { 'xtrabackup-weekly':
130131
ensure => $ensure,
131132
command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir}/$(date +\\%F)_full ${additional_cron_args}",
132-
user => 'root',
133+
user => $backupcronuser,
133134
hour => $time[0],
134135
minute => $time[1],
135136
weekday => '0',
@@ -161,7 +162,7 @@
161162
cron { 'xtrabackup-daily':
162163
ensure => $ensure,
163164
command => "/usr/local/sbin/xtrabackup.sh ${daily_cron_data['directories']} ${additional_cron_args}",
164-
user => 'root',
165+
user => $backupcronuser,
165166
hour => $time[0],
166167
minute => $time[1],
167168
weekday => $daily_cron_data['weekday'],
@@ -180,7 +181,7 @@
180181
ensure => $ensure,
181182
path => '/usr/local/sbin/xtrabackup.sh',
182183
mode => '0700',
183-
owner => 'root',
184+
owner => $backupcronuser,
184185
group => $mysql::params::root_group,
185186
content => template($backupscript_template),
186187
}

Diff for: manifests/params.pp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class mysql::params {
77
$manage_config_file = true
88
$config_file_mode = '0644'
9+
$backupcronuser = 'root'
910
$purge_conf_dir = false
1011
$restart = false
1112
$root_password = 'UNSET'

Diff for: manifests/server/backup.pp

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#
2525
# @param backupuser
2626
# MySQL user to create with backup administrator privileges.
27+
# @param backupcronuser
28+
# User to use for backup cron jobs. Defaults to root.
2729
# @param backuppassword
2830
# Password to create for `backupuser`.
2931
# @param backupdir
@@ -84,6 +86,7 @@
8486
# Give a list of excluded databases when using file_per_database, e.g.: [ 'information_schema', 'performance_schema' ]
8587
class mysql::server::backup (
8688
$backupuser = undef,
89+
$backupcronuser = $mysql::params::backupcronuser,
8790
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
8891
$backupdir = undef,
8992
$backupdirmode = '0700',
@@ -121,10 +124,11 @@
121124
create_resources('class', {
122125
"mysql::backup::${provider}" => {
123126
'backupuser' => $backupuser,
127+
'backupcronuser' => $backupcronuser,
124128
'backuppassword' => $backuppassword,
125129
'backupdir' => $backupdir,
126130
'backupdirmode' => $backupdirmode,
127-
'backupdirowner' => $backupdirowner,
131+
'backupdirowner' => $backupcronuser,
128132
'backupdirgroup' => $backupdirgroup,
129133
'backupcompress' => $backupcompress,
130134
'backuprotate' => $backuprotate,

0 commit comments

Comments
 (0)