]>
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 # Backup using global exclude/include definitions
61 tar cvfz
"${filename}" -C
/ \
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
/ \
76 --exclude
-from
="/var/ipfire/backup/exclude" \
77 --exclude
-from
="/var/ipfire/backup/exclude.user"; then
78 echo
"Could not extract backup" >&2
82 # Restart syslogd, httpd and suricata in case we've just loaded old logs
84 /bin/kill -HUP
`cat /var/run/suricata.pid 2> /dev/null` 2> /dev
/null
85 /bin/kill -HUP
`cat /var/run/syslogd.pid 2> /dev/null` 2> /dev
/null
87 # remove wrong vnstat tag file
88 rm
-f
/var/log/vnstat/tag
92 useradd
-c
'dhcpcd privsep user' \
93 -d
/run/dhcpcd
/chroot \
101 if [ -d
"/var/ipfire/outgoing" ]; then
104 for file
in /var/ipfire
/firewall/{config
,outgoing
} \
105 /var/ipfire
/fwhosts/custo
m{hosts,groups,networks}; do
107 chown nobody
:nobody
"${file}"
113 # Remove old configuration
114 rm
-rf
"/var/ipfire/outgoing"
118 if [ -d
"/var/ipfire/xtaccess" ]; then
119 : > /var/ipfire
/firewall/config
120 chown nobody
:nobody
"/var/ipfire/firewall/config"
125 # Remove old configuration
126 rm
-rf
"/var/ipfire/xtaccess"
130 if [ -d
"/var/ipfire/dmzholes" ] || [ -d
"/var/ipfire/portfw" ]; then
131 : > /var/ipfire
/firewall/config
132 chown nobody
:nobody
"/var/ipfire/firewall/config"
137 # Remove old configuration
138 rm
-rf
"/var/ipfire/dmzholes"
142 if [ -d
"/var/ipfire/portfw" ]; then
146 # Remove old configuration
147 rm
-rf
"/var/ipfire/portfw"
156 # Convert old OpenVPN CCD files (CN change, Core Update 75)
159 # Snort to suricata converter.
160 if [ -d
"/var/ipfire/snort" ]; then
164 # Remove old configuration directory.
165 rm
-rf
"/var/ipfire/snort"
168 # IDS multiple providers converter.
169 if [ -e
"/var/ipfire/suricata/rules-settings" ]; then
171 convert
-ids
-multiple
-providers
174 # Convert DNS settings
177 # move nobeeps if exist
178 [ -e
"/var/ipfire/ppp/nobeeps" ] && mv
/var/ipfire
/ppp/nobeeps
/var/ipfire
/red/nobeeps
184 local filelist
=( /var/log/messages* /var
/log/*.log /var/log/**/*.log )
186 echo
"${filelist[@]}"
189 make_addon_backup
() {
193 if [ ! -f
"/var/ipfire/backup/addons/includes/${name}" ]; then
194 echo
"${name} does not have any backup includes" >&2
198 local filename
="/var/ipfire/backup/addons/backup/${name}.ipf"
200 tar cvzf
"${filename}" \
201 $(process_includes
"/var/ipfire/backup/addons/includes/${name}")
204 restore_addon_backup
() {
207 if [ -d
"/tmp/${name}.ipf" ]; then
208 mv
"/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
212 if ! tar xvzpf
"/var/ipfire/backup/addons/backup/${name}.ipf" -C
/; then
213 echo
"Could not extract backup" >&2
224 local filename
="${1}"
226 if [ -z
"${filename}" ]; then
227 filename
="/var/ipfire/backup/${NOW}.ipf"
230 make_backup
"${filename}" $(find_logfiles
)
234 local filename
="${1}"
236 if [ -z
"${filename}" ]; then
237 filename
="/var/ipfire/backup/${NOW}.ipf"
240 make_backup
"${filename}"
244 local filename
="${1}"
246 if [ -z
"${filename}" ]; then
247 filename
="/tmp/restore.ipf"
250 restore_backup
"${filename}"
254 make_addon_backup
"$@"
258 restore_addon_backup
"${1/.ipf/}"
262 # Desired backup filename
263 local filename
="/var/ipfire/backup/${NOW}.ipf"
265 if make_backup
"${filename}"; then
266 /usr/local/bin/backupiso
"${NOW}"
271 mkdir -p
/var/ipfire
/backup/addons
/{backup
,includes
}
275 process_includes
"/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
278 /var/ipfire
/backup/*.ipf
|/var/ipfire
/backup/addon
s/backup/*.ipf|/var
/tmp/backupiso
/*.iso
)
283 echo
"${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2