]>
git.ipfire.org Git - people/pmueller/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 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") \
72 tar xvzpf
"${filename}" -C
/
74 # Restart syslogd, httpd and suricata in case we've just loaded old logs
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
82 if [ -d
"/var/ipfire/outgoing" ]; then
85 for file
in /var/ipfire
/firewall/{config
,outgoing
} \
86 /var/ipfire
/fwhosts/custo
m{hosts,groups,networks}; do
88 chown nobody
:nobody
"${file}"
94 # Remove old configuration
95 rm
-rf
"/var/ipfire/outgoing"
99 if [ -d
"/var/ipfire/xtaccess" ]; then
100 : > /var/ipfire
/firewall/config
101 chown nobody
:nobody
"/var/ipfire/firewall/config"
106 # Remove old configuration
107 rm
-rf
"/var/ipfire/xtaccess"
111 if [ -d
"/var/ipfire/dmzholes" ] || [ -d
"/var/ipfire/portfw" ]; then
112 : > /var/ipfire
/firewall/config
113 chown nobody
:nobody
"/var/ipfire/firewall/config"
118 # Remove old configuration
119 rm
-rf
"/var/ipfire/dmzholes"
123 if [ -d
"/var/ipfire/portfw" ]; then
127 # Remove old configuration
128 rm
-rf
"/var/ipfire/portfw"
134 # Convert old OpenVPN CCD files (CN change, Core Update 75)
137 # Snort to suricata converter.
138 if [ -d
"/var/ipfire/snort" ]; then
142 # Remove old configuration directory.
143 rm
-rf
"/var/ipfire/snort"
146 # Convert DNS settings
153 local filelist
=( /var/log/messages* /var
/log/*.log /var/log/**/*.log )
155 echo
"${filelist[@]}"
158 make_addon_backup
() {
162 if [ ! -f
"/var/ipfire/backup/addons/includes/${name}" ]; then
163 echo
"${name} does not have any backup includes" >&2
167 local filename
="/var/ipfire/backup/addons/backup/${name}.ipf"
169 tar cvzf
"${filename}" \
170 $(process_includes
"/var/ipfire/backup/addons/includes/${name}")
173 restore_addon_backup
() {
176 if [ -d
"/tmp/${name}.ipf" ]; then
177 mv
"/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
180 tar xvzpf
"/var/ipfire/backup/addons/backup/${name}.ipf" -C
/
189 local filename
="${1}"
191 if [ -z
"${filename}" ]; then
192 filename
="/var/ipfire/backup/${NOW}.ipf"
195 make_backup
"${filename}" $(find_logfiles
)
199 local filename
="${1}"
201 if [ -z
"${filename}" ]; then
202 filename
="/var/ipfire/backup/${NOW}.ipf"
205 make_backup
"${filename}"
209 local filename
="${1}"
211 if [ -z
"${filename}" ]; then
212 filename
="/tmp/restore.ipf"
215 restore_backup
"/tmp/restore.ipf"
219 make_addon_backup
"$@"
223 restore_addon_backup
"${1/.ipf/}"
227 # Desired backup filename
228 local filename
="/var/ipfire/backup/${NOW}.ipf"
230 if make_backup
"${filename}"; then
231 /usr/local/bin/backupiso
"${NOW}" &
236 mkdir -p
/var/ipfire
/backup/addons
/{backup
,includes
}
240 process_includes
"/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
243 /var/ipfire
/backup/*.ipf
|/var/ipfire
/backup/addon
s/backup/*.ipf|/var
/tmp/backupiso
/*.iso
)
248 echo
"${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2