forked from puppetlabs/puppetlabs-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.pp
123 lines (120 loc) · 5.05 KB
/
backup.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# @summary
# Create and manage a MySQL backup.
#
# @example Create a basic MySQL backup:
# class { 'mysql::server':
# root_password => 'password'
# }
# class { 'mysql::server::backup':
# backupuser => 'myuser',
# backuppassword => 'mypassword',
# backupdir => '/tmp/backups',
# }
# class { 'mysql::server::backup':
# backupmethod => 'mariabackup',
# provider => 'xtrabackup',
# backupdir => '/tmp/backups',
# }
#
# @param backupuser
# MySQL user with backup administrator privileges.
# @param backuppassword
# Password for `backupuser`.
# @param backupdir
# Directory to store backup.
# @param backupdirmode
# Permissions applied to the backup directory. This parameter is passed directly to the file resource.
# @param backupdirowner
# Owner for the backup directory. This parameter is passed directly to the file resource.
# @param backupdirgroup
# Group owner for the backup directory. This parameter is passed directly to the file resource.
# @param backupcompress
# Whether or not to compress the backup (when using the mysqldump provider)
# @param backupmethod
# The execution binary for backing up. ex. mysqldump, xtrabackup, mariabackup
# @param backuprotate
# Backup rotation interval in 24 hour periods.
# @param ignore_events
# Ignore the mysql.event table.
# @param delete_before_dump
# Whether to delete old .sql files before backing up. Setting to true deletes old files before backing up, while setting to false deletes them after backup.
# @param backupdatabases
# Databases to backup (if using xtrabackup provider).
# @param file_per_database
# Use file per database mode creating one file per database backup.
# @param include_routines
# Dump stored routines (procedures and functions) from dumped databases when doing a `file_per_database` backup.
# @param include_triggers
# Dump triggers for each dumped table when doing a `file_per_database` backup.
# @param ensure
# @param time
# An array of two elements to set the backup time. Allows ['23', '5'] (i.e., 23:05) or ['3', '45'] (i.e., 03:45) for HH:MM times.
# @param prescript
# A script that is executed before the backup begins.
# @param postscript
# A script that is executed when the backup is finished. This could be used to sync the backup to a central store. This script can be either a single line that is directly executed or a number of lines supplied as an array. It could also be one or more externally managed (executable) files.
# @param execpath
# Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`.
# @param provider
# Sets the server backup implementation. Valid values are:
# @param maxallowedpacket
# Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.
# @param optional_args
# Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.)
#
class mysql::server::backup (
$backupuser = undef,
$backuppassword = undef,
$backupdir = undef,
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$backupmethod = undef,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
$file_per_database = false,
$include_routines = false,
$include_triggers = false,
$ensure = 'present',
$time = ['23', '5'],
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$provider = 'mysqldump',
$maxallowedpacket = '1M',
$optional_args = [],
) {
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
warning(translate("The 'prescript' option is not currently implemented for the %{provider} backup provider.",
{'provider' => $provider}))
}
create_resources('class', {
"mysql::backup::${provider}" => {
'backupuser' => $backupuser,
'backuppassword' => $backuppassword,
'backupdir' => $backupdir,
'backupdirmode' => $backupdirmode,
'backupdirowner' => $backupdirowner,
'backupdirgroup' => $backupdirgroup,
'backupcompress' => $backupcompress,
'backuprotate' => $backuprotate,
'backupmethod' => $backupmethod,
'ignore_events' => $ignore_events,
'delete_before_dump' => $delete_before_dump,
'backupdatabases' => $backupdatabases,
'file_per_database' => $file_per_database,
'include_routines' => $include_routines,
'include_triggers' => $include_triggers,
'ensure' => $ensure,
'time' => $time,
'prescript' => $prescript,
'postscript' => $postscript,
'execpath' => $execpath,
'maxallowedpacket' => $maxallowedpacket,
'optional_args' => $optional_args,
}
})
}