Add a simple backup server software release.
[slapos.git] / software / backupserver / instance-pullrdiffbackup.cfg.in
1 {% set part_list = [] -%}
2 {% set crontab_line_list = [] -%}
3 ###############################
4 #
5 # Instanciate dcron
6 #
7 ###############################
8
9 [directory]
10 recipe = slapos.cookbook:mkdirectory
11 etc = $${buildout:directory}/etc
12 bin = $${buildout:directory}/bin
13 srv = $${buildout:directory}/srv
14 var = $${buildout:directory}/var
15 log = $${:var}/log
16 # scripts = $${:etc}/run
17 services = $${:etc}/service
18 cron-entries = $${:etc}/cron.d
19 cron-lines = $${:etc}/cron.lines
20 crontabs = $${:etc}/crontabs
21 cronstamps = $${:etc}/cronstamps
22 backup = $${:srv}/backup
23 backupscript = $${:etc}/backup
24 home = $${:etc}/home
25 ssh = $${:home}/.ssh
26
27 #################################
28 # Cron service
29 #################################
30 [dcron-service]
31 recipe = slapos.recipe.template
32 url = ${template-dcron-service:output}
33 output = $${directory:services}/crond
34 mode = 0700
35 logfile = $${directory:log}/crond.log
36
37 #################################
38 # Slave backup scripts and crontab
39 #################################
40 # Go throught slave list to set their configuration
41 {% for slave_instance in slave_instance_list -%}
42 {%   set slave_reference = slave_instance.get('slave_reference') -%}
43 {%   set frequency = slave_instance.get('frequency', '') -%}
44 {%   set hostname = slave_instance.get('hostname', '') -%}
45 {%   set connection = slave_instance.get('connection', '') -%}
46 {%   set include = slave_instance.get('include', '') -%}
47 {%   set include_string = "' --include='".join(include.split(' ')) -%}
48 {%   set exclude = slave_instance.get('exclude', '') -%}
49 {%   set exclude_string = '' -%}
50 {%   set sudo = slave_instance.get('sudo', 'False') -%}
51 {%   set remote_schema = 'rdiff-backup --server --restrict-read-only / -- "$@"' -%}
52
53 {%   if (exclude != '') -%}
54 {%     set exclude_string = "' --exclude='".join(exclude.split(' ')) -%}
55 {%     set exclude_string = "--exclude='" + exclude_string + "'" -%}
56 {%   endif -%}
57
58 {%   if (sudo == 'True') -%}
59 {%     set remote_schema = 'sudo backupagent_rdiff-backup' -%}
60 {%   endif -%}
61
62 {%   if (frequency != '') and (hostname != '') and (connection != '') and (include != '') -%}
63
64 [{{ slave_reference }}-backup-directory]
65 recipe = slapos.cookbook:mkdirectory
66 directory = $${directory:backup}/$${:_buildout_section_name_}
67
68 [{{ slave_reference }}-backup-private_key]
69 recipe = plone.recipe.command
70 stop-on-error = true
71 command = ${dropbear-output:keygen} -t $${:type} -s 2048 -f $${:key} 
72 key = $${directory:ssh}/$${:_buildout_section_name_}
73 location = $${:key}
74 type = rsa
75
76 [{{ slave_reference }}-backup-public_key]
77 recipe = plone.recipe.command
78 stop-on-error = true
79 update-command = $${:command}
80 command = ${coreutils-output:rm} -f $${:key} && ${dropbear-output:keygen} -y -f {{ '$${' ~ slave_reference }}-backup-private_key:key} | ${grep-output:grep} {{ '$${' ~ slave_reference }}-backup-private_key:type} > $${:key}
81 key = {{ '$${' ~ slave_reference }}-backup-private_key:key}.pub
82 location = $${:key}
83
84 [{{ slave_reference }}-backup-check-public_key]
85 recipe = plone.recipe.command
86 stop-on-error = true
87 update-command = $${:command}
88 command = grep ssh-{{ '$${' ~ slave_reference }}-backup-private_key:type} {{ '$${' ~ slave_reference }}-backup-public_key:key}
89
90 [{{ slave_reference }}-backup-read-public_key]
91 recipe = slapos.cookbook:generate.password
92 storage-path = {{ '$${' ~ slave_reference }}-backup-public_key:key}
93 bytes = 8
94
95 # Publish slave {{ slave_reference }} information
96 [{{ slave_reference }}-backup-publish]
97 recipe = slapos.cookbook:publish
98 -slave-reference = {{ slave_reference }}
99 authorized_key = {{ '$${' ~ slave_reference }}-backup-read-public_key:passwd}
100 {%   do part_list.append("%s-backup-publish" % slave_reference) -%}
101
102 [{{ slave_reference }}-backup-script]
103 recipe = slapos.recipe.template
104 url = ${template-backup-script:output}
105 output = $${directory:backupscript}/$${:_buildout_section_name_}
106 mode = 0700
107 datadirectory = {{ '$${' ~ slave_reference }}-backup-directory:directory}
108 sshkey = {{ '$${' ~ slave_reference }}-backup-private_key:key}
109 connection = {{ connection }}
110 hostname = {{ hostname }}
111 include = {{ include_string }}
112 exclude_string = {{ exclude_string }}
113 remote_schema = {{ remote_schema }}
114
115 [{{ slave_reference }}-backup-crontab-line]
116 recipe = slapos.recipe.template
117 url = ${template-crontab-line:output}
118 output = $${directory:cron-lines}/$${:_buildout_section_name_}
119 mode = 0600
120 script = {{ '$${' ~ slave_reference }}-backup-script:output}
121 frequency = {{ frequency }}
122 {%   do crontab_line_list.append("$${%s-backup-crontab-line:output}" % slave_reference) -%}
123
124 {%   endif -%}
125 {% endfor -%}
126
127 #################################
128 # Generate crontab file
129 #################################
130
131 {% set crontab_line_list_string = " ".join(crontab_line_list) -%}
132 [activate-crontab-file]
133 # XXX File is never removed
134 recipe = plone.recipe.command
135 stop-on-error = true
136 update-command = $${:command}
137 command = ${coreutils-output:cat} ${template-crontab:output} {{ crontab_line_list_string }} | ${dcron-output:crontab} -c $${directory:crontabs} -
138
139
140 # Add parts generated by template
141 [buildout]
142 parts =
143   dcron-service
144   activate-crontab-file
145 {% for part in part_list -%}
146 {{ '    %s' % part }}
147 {% endfor -%}
148
149 eggs-directory = ${buildout:eggs-directory}
150 develop-eggs-directory = ${buildout:develop-eggs-directory}
151 offline = true