-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.pp
151 lines (142 loc) · 4.36 KB
/
target.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File:: <tt>bontmia-target.pp</tt>
# Author:: Hyacinthe Cartiaux ([email protected])
# Copyright:: Copyright (c) 2013 Hyacinthe Cartiaux
# License:: GPLv3
#
# ------------------------------------------------------------------------------
# = Defines: bontmia::target
#
# Configure and manage a backup using bontmia
#
# == Pre-requisites
#
# * The class 'bontmia' should have been instanciated
#
# == Parameters:
#
# [*ensure*]
# default to 'present', can be 'absent'.
#
# [*dest_dir*]
# Destination directory of the backup
#
# [*src_dir*], [*src_host*], [*src_user*], [*src_port*]
# Defines the backup source.
# If src_host is not set, it assumes that we want to backup the local directory src_dir
#
# [*rotation*]
# Default: true
# Allow or disable backup rotation
#
# [*rotation_days*], [*rotation_weeks*], [*rotation_months*], [*rotation_years*]
# Set-up the rotation policy with these values, see the bontmia documentation for more information
#
# [*cron_minute*], [*cron_hour*], [*cron_weekday*], [*cron_monthday*], [*cron_month*]
# Set-up a cronjob with these settings
#
# [*email*]
# Send the execution output to this email address
#
# == Sample usage:
#
# include "bontmia"
#
# You can then add a target specification as follows:
#
# class { 'bontmia':
# ensure => 'present',
# prefix => '/data/test2',
# sudo => true
# }
#
# bontmia::target{ 'backup_hcartiaux':
# ensure => 'present',
# dest_dir => '/data/test2/hcartiaux',
# src_user => 'localadmin',
# src_host => 'nfs.chaos',
# src_dir => '/export/users/homedirs/hcartiaux',
# src_port => '8022',
# days => '7',
# weeks => '4',
# months => '12',
# years => '2',
# email => '[email protected]'
# }
#
# == Warnings
#
# /!\ Always respect the style guide available
# here[http://docs.puppetlabs.com/guides/style_guide]
#
# [Remember: No empty lines between comments and class definition]
#
define bontmia::target(
$dest_dir,
$src_dir,
$ensure = 'present',
$src_host = '',
$src_user = 'localadmin',
$src_port = '8022',
$ssh_cipher = 'arcfour',
$rotation = true,
$rotation_days = '7',
$rotation_weeks = '4',
$rotation_months = '12',
$rotation_years = '2',
$cron_minute = '4',
$cron_hour = '4',
$cron_weekday = '*',
$cron_monthday = '*',
$cron_month = '*',
$cron_environment = '',
$email = '',
$backup_owner = $bontmia::params::configfile_owner,
$backup_group = $bontmia::params::configfile_group,
$backup_mode = $bontmia::params::configfile_mode
)
{
include bontmia::params
# $name is provided at define invocation
$basename = $name
$src_dir_array = any2array($src_dir)
if ! ($ensure in [ 'present', 'absent' ]) {
fail("bontmia::target 'ensure' parameter must be set to either 'absent' or 'present'")
}
if ($bontmia::ensure != $ensure) {
if ($bontmia::ensure != 'present') {
fail("Cannot configure a bontmia '${basename}' as bontmia::ensure is NOT set to present (but ${bontmia::ensure})")
}
}
# bash script
file { "${bontmia::prefix}/${basename}.sh":
ensure => $ensure,
owner => $bontmia::params::configfile_owner,
group => $bontmia::params::configfile_group,
mode => $bontmia::params::configfile_mode,
content => template('bontmia/backup.sh.erb'),
require => Exec['install_bontmia'],
}
exec { "mkdir -p ${dest_dir}":
path => [ '/bin', '/usr/bin' ],
unless => "test -d ${dest_dir}",
}
file { $dest_dir:
ensure => 'directory',
owner => $backup_owner,
group => $backup_group,
mode => $backup_mode,
require => Exec["mkdir -p ${dest_dir}"],
}
# cronjob
cron { "bontmia-backup-${basename}":
ensure => $ensure,
command => "${bontmia::prefix}/${basename}.sh",
user => $bontmia::params::bontmia_user,
minute => $cron_minute,
hour => $cron_hour,
weekday => $cron_weekday,
monthday => $cron_monthday,
month => $cron_month,
environment => [ "MAILTO=\"${email}\""] + any2array($cron_environment),
}
}