]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/backup/backup.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
24 NOW
="$(date "+%Y-%m-%d-%H:%M")"
28 for file
in /var/ipfire
/backup/addons
/includes/*; do
29 if [ -f
"${file}" ]; then
41 while read -r file
; do
42 # Skip any empty line (which will include /)
43 [ -n
"${file}" ] || continue
45 for file
in /${file
}; do
46 if [ -e
"${file}" ]; then
58 # Backup all addons first
60 for addon
in $(list_addons
); do
61 make_addon_backup
"${addon}"
64 # Backup using global exclude/include definitions
65 tar cvfz
"${filename}" -C
/ \
66 --exclude
-from
="/var/ipfire/backup/exclude" \
67 --exclude
-from
="/var/ipfire/backup/exclude.user" \
68 $(process_includes
"/var/ipfire/backup/include") \
69 $(process_includes
"/var/ipfire/backup/include.user") \
79 if ! tar xvzpf
"${filename}" -C
/ \
80 --exclude
-from
="/var/ipfire/backup/exclude" \
81 --exclude
-from
="/var/ipfire/backup/exclude.user"; then
82 echo
"Could not extract backup" >&2
86 # Restart syslogd, httpd and suricata in case we've just loaded old logs
88 /bin/kill -HUP
`cat /var/run/suricata.pid 2> /dev/null` 2> /dev
/null
89 /bin/kill -HUP
`cat /var/run/syslogd.pid 2> /dev/null` 2> /dev
/null
91 # remove wrong vnstat tag file
92 rm
-f
/var/log/vnstat/tag
96 useradd
-c
'dhcpcd privsep user' \
97 -d
/run/dhcpcd
/chroot \
105 if [ -d
"/var/ipfire/outgoing" ]; then
108 for file
in /var/ipfire
/firewall/{config
,outgoing
} \
109 /var/ipfire
/fwhosts/custo
m{hosts,groups,networks}; do
111 chown nobody
:nobody
"${file}"
117 # Remove old configuration
118 rm
-rf
"/var/ipfire/outgoing"
122 if [ -d
"/var/ipfire/xtaccess" ]; then
123 : > /var/ipfire
/firewall/config
124 chown nobody
:nobody
"/var/ipfire/firewall/config"
129 # Remove old configuration
130 rm
-rf
"/var/ipfire/xtaccess"
134 if [ -d
"/var/ipfire/dmzholes" ] || [ -d
"/var/ipfire/portfw" ]; then
135 : > /var/ipfire
/firewall/config
136 chown nobody
:nobody
"/var/ipfire/firewall/config"
141 # Remove old configuration
142 rm
-rf
"/var/ipfire/dmzholes"
146 if [ -d
"/var/ipfire/portfw" ]; then
150 # Remove old configuration
151 rm
-rf
"/var/ipfire/portfw"
160 # Convert old OpenVPN CCD files (CN change, Core Update 75)
163 # Snort to suricata converter.
164 if [ -d
"/var/ipfire/snort" ]; then
168 # Remove old configuration directory.
169 rm
-rf
"/var/ipfire/snort"
172 # IDS multiple providers converter.
173 if [ -e
"/var/ipfire/suricata/rules-settings" ]; then
175 convert
-ids
-multiple
-providers
178 # IDS backend converter.
179 if [ -e
"/var/ipfire/suricata/oinkmaster.conf" ]; then
181 convert
-ids
-backend
-files
184 # Convert DNS settings
187 # move nobeeps if exist
188 [ -e
"/var/ipfire/ppp/nobeeps" ] && mv
/var/ipfire
/ppp/nobeeps
/var/ipfire
/red/nobeeps
194 local filelist
=( /var/log/logwatch/* /var/log/messages* /var
/log/*.log /var/log/**/*.log )
196 echo
"${filelist[@]}"
199 make_addon_backup
() {
203 if [ ! -f
"/var/ipfire/backup/addons/includes/${name}" ]; then
204 echo
"${name} does not have any backup includes" >&2
208 local filename
="/var/ipfire/backup/addons/backup/${name}.ipf"
210 tar cvzf
"${filename}" \
211 $(process_includes
"/var/ipfire/backup/addons/includes/${name}")
214 restore_addon_backup
() {
217 if [ -d
"/tmp/${name}.ipf" ]; then
218 mv
"/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
222 if ! tar xvzpf
"/var/ipfire/backup/addons/backup/${name}.ipf" -C
/; then
223 echo
"Could not extract backup" >&2
234 local filename
="${1}"
236 if [ -z
"${filename}" ]; then
237 filename
="/var/ipfire/backup/${NOW}.ipf"
240 make_backup
"${filename}" $(find_logfiles
)
244 local filename
="${1}"
246 if [ -z
"${filename}" ]; then
247 filename
="/var/ipfire/backup/${NOW}.ipf"
250 make_backup
"${filename}"
254 local filename
="${1}"
256 if [ -z
"${filename}" ]; then
257 filename
="/tmp/restore.ipf"
260 restore_backup
"${filename}"
264 make_addon_backup
"$@"
268 restore_addon_backup
"${1/.ipf/}"
272 # Desired backup filename
273 local filename
="/var/ipfire/backup/${NOW}.ipf"
275 if make_backup
"${filename}"; then
276 /usr/local/bin/backupiso
"${NOW}"
281 mkdir -p
/var/ipfire
/backup/addons
/{backup
,includes
}
285 process_includes
"/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
288 /var/ipfire
/backup/*.ipf
|/var/ipfire
/backup/addon
s/backup/*.ipf|/var
/tmp/backupiso
/*.iso
)
293 echo
"${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2