]>
git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - config/backup/backup.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2014 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 ###############################################################################
22 NOW
="$(date "+%Y-%m-%d-%H:%M")"
26 for file
in /var/ipfire
/backup/addons
/includes/*; do
27 if [ -f
"${file}" ]; then
40 while read -r file
; do
41 for file
in ${file
}; do
42 if [ -e
"${file}" ]; then
54 # Backup all addons first
56 for addon
in $(list_addons
); do
57 make_addon_backup
"${addon}"
60 # Backup using global exclude/include definitions
61 tar cvfz
"${filename}" \
62 --exclude
-from
="/var/ipfire/backup/exclude" \
63 --exclude
-from
="/var/ipfire/backup/exclude.user" \
64 $(process_includes
"/var/ipfire/backup/include") \
65 $(process_includes
"/var/ipfire/backup/include.user") \
75 if ! tar xvzpf
"${filename}" -C
/; then
76 echo
"Could not extract backup" >&2
80 # Restart syslogd, httpd and suricata in case we've just loaded old logs
82 /bin/kill -HUP
`cat /var/run/suricata.pid 2> /dev/null` 2> /dev
/null
83 /bin/kill -HUP
`cat /var/run/syslogd.pid 2> /dev/null` 2> /dev
/null
85 # remove wrong vnstat tag file
86 rm
-f
/var/log/vnstat/tag
90 useradd
-c
'dhcpcd privsep user' \
91 -d
/run/dhcpcd
/chroot \
99 if [ -d
"/var/ipfire/outgoing" ]; then
102 for file
in /var/ipfire
/firewall/{config
,outgoing
} \
103 /var/ipfire
/fwhosts/custo
m{hosts,groups,networks}; do
105 chown nobody
:nobody
"${file}"
111 # Remove old configuration
112 rm
-rf
"/var/ipfire/outgoing"
116 if [ -d
"/var/ipfire/xtaccess" ]; then
117 : > /var/ipfire
/firewall/config
118 chown nobody
:nobody
"/var/ipfire/firewall/config"
123 # Remove old configuration
124 rm
-rf
"/var/ipfire/xtaccess"
128 if [ -d
"/var/ipfire/dmzholes" ] || [ -d
"/var/ipfire/portfw" ]; then
129 : > /var/ipfire
/firewall/config
130 chown nobody
:nobody
"/var/ipfire/firewall/config"
135 # Remove old configuration
136 rm
-rf
"/var/ipfire/dmzholes"
140 if [ -d
"/var/ipfire/portfw" ]; then
144 # Remove old configuration
145 rm
-rf
"/var/ipfire/portfw"
154 # Convert old OpenVPN CCD files (CN change, Core Update 75)
157 # Snort to suricata converter.
158 if [ -d
"/var/ipfire/snort" ]; then
162 # Remove old configuration directory.
163 rm
-rf
"/var/ipfire/snort"
166 # IDS multiple providers converter.
167 if [ -e
"/var/ipfire/suricata/rules-settings" ]; then
169 convert
-ids
-multiple
-providers
172 # Convert DNS settings
175 # move nobeeps if exist
176 [ -e
"/var/ipfire/ppp/nobeeps" ] && mv
/var/ipfire
/ppp/nobeeps
/var/ipfire
/red/nobeeps
182 local filelist
=( /var/log/messages* /var
/log/*.log /var/log/**/*.log )
184 echo
"${filelist[@]}"
187 make_addon_backup
() {
191 if [ ! -f
"/var/ipfire/backup/addons/includes/${name}" ]; then
192 echo
"${name} does not have any backup includes" >&2
196 local filename
="/var/ipfire/backup/addons/backup/${name}.ipf"
198 tar cvzf
"${filename}" \
199 $(process_includes
"/var/ipfire/backup/addons/includes/${name}")
202 restore_addon_backup
() {
205 if [ -d
"/tmp/${name}.ipf" ]; then
206 mv
"/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
210 if ! tar xvzpf
"/var/ipfire/backup/addons/backup/${name}.ipf" -C
/; then
211 echo
"Could not extract backup" >&2
222 local filename
="${1}"
224 if [ -z
"${filename}" ]; then
225 filename
="/var/ipfire/backup/${NOW}.ipf"
228 make_backup
"${filename}" $(find_logfiles
)
232 local filename
="${1}"
234 if [ -z
"${filename}" ]; then
235 filename
="/var/ipfire/backup/${NOW}.ipf"
238 make_backup
"${filename}"
242 local filename
="${1}"
244 if [ -z
"${filename}" ]; then
245 filename
="/tmp/restore.ipf"
248 restore_backup
"${filename}"
252 make_addon_backup
"$@"
256 restore_addon_backup
"${1/.ipf/}"
260 # Desired backup filename
261 local filename
="/var/ipfire/backup/${NOW}.ipf"
263 if make_backup
"${filename}"; then
264 /usr/local/bin/backupiso
"${NOW}"
269 mkdir -p
/var/ipfire
/backup/addons
/{backup
,includes
}
273 process_includes
"/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
276 /var/ipfire
/backup/*.ipf
|/var/ipfire
/backup/addon
s/backup/*.ipf|/var
/tmp/backupiso
/*.iso
)
281 echo
"${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2