]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/backup/backup.pl
unbound: try resolve twice before time sync with ipfire server
[people/pmueller/ipfire-2.x.git] / config / backup / backup.pl
CommitLineData
c7b7a70d 1#!/bin/bash
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
2b4593b2 5# Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
cf29614f 21
c7b7a70d
MT
22NOW="$(date "+%Y-%m-%d-%H:%M")"
23
24list_addons() {
25 local file
26 for file in /var/ipfire/backup/addons/includes/*; do
27 if [ -f "${file}" ]; then
28 basename "${file}"
29 fi
30 done
31
32 return 0
8e8bbd9d 33}
c7b7a70d
MT
34
35process_includes() {
36 local include
37
38 for include in $@; do
39 local file
40 while read -r file; do
4f10c0b3 41 for file in ${file}; do
c7b7a70d
MT
42 if [ -e "${file}" ]; then
43 echo "${file}"
44 fi
4f10c0b3 45 done
c7b7a70d
MT
46 done < "${include}"
47 done | sort -u
5ad5a6bc 48}
c7b7a70d
MT
49
50make_backup() {
51 local filename="${1}"
52 shift
53
54 # Backup all addons first
55 local addon
56 for addon in $(list_addons); do
57 make_addon_backup "${addon}"
58 done
59
60 tar cvzf "${filename}" \
61 --exclude-from="/var/ipfire/backup/exclude" \
62 --exclude-from="/var/ipfire/backup/exclude.user" \
63 $(process_includes "/var/ipfire/backup/include" "/var/ipfire/backup/include.user") \
64 "$@"
65
66 return 0
cf29614f 67}
c7b7a70d
MT
68
69restore_backup() {
70 local filename="${1}"
71
72 tar xvzpf "${filename}" -C /
73
28797d48
TF
74 # Restart syslogd, httpd and suricata in case we've just loaded old logs
75 apachectl -k graceful
76 /bin/kill -HUP `cat /var/run/suricata.pid 2> /dev/null` 2> /dev/null
77 /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null
78
c7b7a70d
MT
79 # Run converters
80
81 # Outgoing Firewall
82 if [ -d "/var/ipfire/outgoing" ]; then
83 # Reset files
84 local file
85 for file in /var/ipfire/firewall/{config,outgoing} \
86 /var/ipfire/fwhosts/custom{hosts,groups,networks}; do
87 : > "${file}"
88 chown nobody:nobody "${file}"
89 done
90
91 # Run converter
92 convert-outgoingfw
93
94 # Remove old configuration
95 rm -rf "/var/ipfire/outgoing"
96 fi
97
98 # External Access
99 if [ -d "/var/ipfire/xtaccess" ]; then
100 : > /var/ipfire/firewall/config
101 chown nobody:nobody "/var/ipfire/firewall/config"
102
103 # Run converter
104 convert-xtaccess
105
106 # Remove old configuration
107 rm -rf "/var/ipfire/xtaccess"
108 fi
109
110 # DMZ Holes
111 if [ -d "/var/ipfire/dmzholes" ] || [ -d "/var/ipfire/portfw" ]; then
112 : > /var/ipfire/firewall/config
113 chown nobody:nobody "/var/ipfire/firewall/config"
114
115 # Run converter
116 convert-dmz
117
118 # Remove old configuration
119 rm -rf "/var/ipfire/dmzholes"
120 fi
121
122 # Port Forwardings
123 if [ -d "/var/ipfire/portfw" ]; then
124 # Run converter
125 convert-portfw
126
127 # Remove old configuration
128 rm -rf "/var/ipfire/portfw"
129 fi
130
131 # Reload firewall
132 firewallctrl
133
134 # Convert old OpenVPN CCD files (CN change, Core Update 75)
135 convert-ovpn
136
8c273724
SS
137 # Snort to suricata converter.
138 if [ -d "/var/ipfire/snort" ]; then
139 # Run converter
140 convert-snort
141
142 # Remove old configuration directory.
143 rm -rf "/var/ipfire/snort"
144 fi
145
ecbf6676
MT
146 # Convert DNS settings
147 convert-dns-settings
148
6df8a22b
AF
149 # move nobeeps if exist
150 [ -e "/var/ipfire/ppp/nobeeps" ] && mv /var/ipfire/ppp/nobeeps /var/ipfire/red/nobeeps
151
c7b7a70d 152 return 0
901a50cf 153}
c7b7a70d
MT
154
155find_logfiles() {
156 local filelist=( /var/log/messages* /var/log/*.log /var/log/**/*.log )
157
158 echo "${filelist[@]}"
b90a7e56 159}
c7b7a70d
MT
160
161make_addon_backup() {
162 local name="${1}"
163 shift
164
165 if [ ! -f "/var/ipfire/backup/addons/includes/${name}" ]; then
166 echo "${name} does not have any backup includes" >&2
167 return 1
168 fi
169
170 local filename="/var/ipfire/backup/addons/backup/${name}.ipf"
171
172 tar cvzf "${filename}" \
173 $(process_includes "/var/ipfire/backup/addons/includes/${name}")
8e8bbd9d 174}
c7b7a70d
MT
175
176restore_addon_backup() {
177 local name="${1}"
178
179 if [ -d "/tmp/${name}.ipf" ]; then
180 mv "/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
181 fi
182
183 tar xvzpf "/var/ipfire/backup/addons/backup/${name}.ipf" -C /
a609bfb0 184}
8e8bbd9d 185
c7b7a70d
MT
186main() {
187 local command="${1}"
188 shift
189
c7b7a70d
MT
190 case "${command}" in
191 include)
175f5c06
MT
192 local filename="${1}"
193
194 if [ -z "${filename}" ]; then
195 filename="/var/ipfire/backup/${NOW}.ipf"
196 fi
197
c7b7a70d
MT
198 make_backup "${filename}" $(find_logfiles)
199 ;;
200
201 exclude)
175f5c06
MT
202 local filename="${1}"
203
204 if [ -z "${filename}" ]; then
205 filename="/var/ipfire/backup/${NOW}.ipf"
206 fi
207
c7b7a70d
MT
208 make_backup "${filename}"
209 ;;
210
211 restore)
175f5c06
MT
212 local filename="${1}"
213
214 if [ -z "${filename}" ]; then
215 filename="/tmp/restore.ipf"
216 fi
217
c7b7a70d
MT
218 restore_backup "/tmp/restore.ipf"
219 ;;
220
221 addonbackup)
222 make_addon_backup "$@"
223 ;;
cf29614f 224
c7b7a70d
MT
225 restoreaddon)
226 restore_addon_backup "${1/.ipf/}"
227 ;;
84578512 228
c7b7a70d 229 iso)
175f5c06
MT
230 # Desired backup filename
231 local filename="/var/ipfire/backup/${NOW}.ipf"
232
c7b7a70d
MT
233 if make_backup "${filename}"; then
234 /usr/local/bin/backupiso "${NOW}" &
235 fi
236 ;;
237
238 makedirs)
239 mkdir -p /var/ipfire/backup/addons/{backup,includes}
240 ;;
241
4f10c0b3
MT
242 list)
243 process_includes "/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
244 ;;
245
c7b7a70d
MT
246 /var/ipfire/backup/*.ipf|/var/ipfire/backup/addons/backup/*.ipf|/var/tmp/backupiso/*.iso)
247 unlink "${command}"
248 ;;
249
250 *)
251 echo "${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2
252 return 2
253 ;;
254 esac
255
256 return $?
cf29614f 257}
c7b7a70d
MT
258
259main "$@" || exit $?