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
|
class role::backup (
String $user,
String $group,
String $mailto,
Optional[Array] $backups = [],
Optional[String] $mountpoint = "/backup1",
Optional[String] $backup_script = "/usr/local/bin/backup.sh",
) {
include "base_installation"
include "profile::fstab"
include "profile::mail"
include "profile::tools"
include "profile::xmr_stak"
include "profile::known_hosts"
include "profile::boinc"
ensure_packages(["rsync"])
ssh_keygen { $user:
notify => Notify_refresh["notify-backup-sshkey-change"]
}
$hosts = $backups.map |$backup| { $backup["host"] }
notify_refresh { "notify-backup-sshkey-change":
message => template("role/backup/ssh_key_changed.info.erb"),
refreshonly => true
}
$hosts.each |$host| {
notify_refresh { "notify-backup-sshhost-$host-changed":
message => template("role/backup/ssh_host_changed.info.erb"),
refreshonly => true,
subscribe => Sshkey[$host],
}
}
concat { $backup_script:
ensure => "present",
ensure_newline => true,
mode => "0755",
}
cron::job { "backup":
ensure => present,
command => $backup_script,
user => $user,
minute => 25,
hour => "3,15",
require => Concat[$backup_script],
}
concat::fragment { "backup_head":
target => $backup_script,
content => template("role/backup/backup_head.sh.erb"),
order => "01-50",
}
concat::fragment { "backup_tail":
target => $backup_script,
content => template("role/backup/backup_tail.sh.erb"),
order => "99-50",
}
$backups.each |$infos| {
$dirname = $infos["name"]
$login = $infos["login"]
$host = $infos["host"]
$dest = "$login@$host"
$base = "$mountpoint/$dirname"
$nbr = $infos["nbr"]
$order_dirname = $infos["order"]
file { $base:
ensure => "directory",
owner => $user,
group => $group,
require => Mount[$mountpoint],
} ->
file { "$base/older":
ensure => "directory",
owner => $user,
group => $group,
} ->
file { "$base/rsync_output":
ensure => "directory",
owner => $user,
group => $group,
}
concat::fragment { "backup_${dirname}_head":
target => $backup_script,
content => template("role/backup/backup_dirname_head.sh.erb"),
order => "$order_dirname-01",
}
concat::fragment { "backup_${dirname}_tail":
target => $backup_script,
content => template("role/backup/backup_dirname_tail.sh.erb"),
order => "$order_dirname-99",
}
$infos["parts"].each |$part| {
$local_folder = $part["local_folder"]
$remote_folder = $part["remote_folder"]
$exclude_from = $part["exclude_from"]
$files_from = $part["files_from"]
$args = $part["args"]
$order_part = $part["order"]
file { "$base/$local_folder":
ensure => "directory",
owner => $user,
group => $group,
require => File[$base],
}
concat::fragment { "backup_${dirname}_${local_folder}":
target => $backup_script,
content => template("role/backup/backup_dirname_part.sh.erb"),
order => "$order_dirname-$order_part",
}
}
}
}
|