]>
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 cvf
"${filename}" \
62 --exclude
-from
="/var/ipfire/backup/exclude" \
63 $(process_includes
"/var/ipfire/backup/include") \
66 # Backup using user exclude/include definitions and append to global backup
67 tar rvf
"${filename}" \
68 --exclude
-from
="/var/ipfire/backup/exclude.user" \
69 $(process_includes
"/var/ipfire/backup/include.user") \
72 # gzip the combined global/user backup and use .ipf suffix
73 gzip
--suffix
.ipf
"${filename}"
81 tar xvzpf
"${filename}" -C
/
83 # Restart syslogd, httpd and suricata in case we've just loaded old logs
85 /bin/kill -HUP
`cat /var/run/suricata.pid 2> /dev/null` 2> /dev
/null
86 /bin/kill -HUP
`cat /var/run/syslogd.pid 2> /dev/null` 2> /dev
/null
88 # remove wrong vnstat tag file
89 rm
-f
/var/log/vnstat/tag
93 useradd
-c
'dhcpcd privsep user' \
94 -d
/run/dhcpcd
/chroot \
102 if [ -d
"/var/ipfire/outgoing" ]; then
105 for file
in /var/ipfire
/firewall/{config
,outgoing
} \
106 /var/ipfire
/fwhosts/custo
m{hosts,groups,networks}; do
108 chown nobody
:nobody
"${file}"
114 # Remove old configuration
115 rm
-rf
"/var/ipfire/outgoing"
119 if [ -d
"/var/ipfire/xtaccess" ]; then
120 : > /var/ipfire
/firewall/config
121 chown nobody
:nobody
"/var/ipfire/firewall/config"
126 # Remove old configuration
127 rm
-rf
"/var/ipfire/xtaccess"
131 if [ -d
"/var/ipfire/dmzholes" ] || [ -d
"/var/ipfire/portfw" ]; then
132 : > /var/ipfire
/firewall/config
133 chown nobody
:nobody
"/var/ipfire/firewall/config"
138 # Remove old configuration
139 rm
-rf
"/var/ipfire/dmzholes"
143 if [ -d
"/var/ipfire/portfw" ]; then
147 # Remove old configuration
148 rm
-rf
"/var/ipfire/portfw"
157 # Convert old OpenVPN CCD files (CN change, Core Update 75)
160 # Snort to suricata converter.
161 if [ -d
"/var/ipfire/snort" ]; then
165 # Remove old configuration directory.
166 rm
-rf
"/var/ipfire/snort"
169 # Convert DNS settings
172 # move nobeeps if exist
173 [ -e
"/var/ipfire/ppp/nobeeps" ] && mv
/var/ipfire
/ppp/nobeeps
/var/ipfire
/red/nobeeps
179 local filelist
=( /var/log/messages* /var
/log/*.log /var/log/**/*.log )
181 echo
"${filelist[@]}"
184 make_addon_backup
() {
188 if [ ! -f
"/var/ipfire/backup/addons/includes/${name}" ]; then
189 echo
"${name} does not have any backup includes" >&2
193 local filename
="/var/ipfire/backup/addons/backup/${name}.ipf"
195 tar cvzf
"${filename}" \
196 $(process_includes
"/var/ipfire/backup/addons/includes/${name}")
199 restore_addon_backup
() {
202 if [ -d
"/tmp/${name}.ipf" ]; then
203 mv
"/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
206 tar xvzpf
"/var/ipfire/backup/addons/backup/${name}.ipf" -C
/
215 local filename
="${1}"
217 if [ -z
"${filename}" ]; then
218 filename
="/var/ipfire/backup/${NOW}"
221 make_backup
"${filename}" $(find_logfiles
)
225 local filename
="${1}"
227 if [ -z
"${filename}" ]; then
228 filename
="/var/ipfire/backup/${NOW}"
231 make_backup
"${filename}"
235 local filename
="${1}"
237 if [ -z
"${filename}" ]; then
238 filename
="/tmp/restore.ipf"
241 restore_backup
"/tmp/restore.ipf"
245 make_addon_backup
"$@"
249 restore_addon_backup
"${1/.ipf/}"
253 # Desired backup filename
254 local filename
="/var/ipfire/backup/${NOW}.ipf"
256 if make_backup
"${filename}"; then
257 /usr/local/bin/backupiso
"${NOW}" &
262 mkdir -p
/var/ipfire
/backup/addons
/{backup
,includes
}
266 process_includes
"/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
269 /var/ipfire
/backup/*.ipf
|/var/ipfire
/backup/addon
s/backup/*.ipf|/var
/tmp/backupiso
/*.iso
)
274 echo
"${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2