]>
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
79 # remove wrong vnstat tag file
80 rm
-f
/var/log/vnstat/tag
84 useradd
-c
'dhcpcd privsep user' \
85 -d
/run/dhcpcd
/chroot \
93 if [ -d
"/var/ipfire/outgoing" ]; then
96 for file
in /var/ipfire
/firewall/{config
,outgoing
} \
97 /var/ipfire
/fwhosts/custo
m{hosts,groups,networks}; do
99 chown nobody
:nobody
"${file}"
105 # Remove old configuration
106 rm
-rf
"/var/ipfire/outgoing"
110 if [ -d
"/var/ipfire/xtaccess" ]; then
111 : > /var/ipfire
/firewall/config
112 chown nobody
:nobody
"/var/ipfire/firewall/config"
117 # Remove old configuration
118 rm
-rf
"/var/ipfire/xtaccess"
122 if [ -d
"/var/ipfire/dmzholes" ] || [ -d
"/var/ipfire/portfw" ]; then
123 : > /var/ipfire
/firewall/config
124 chown nobody
:nobody
"/var/ipfire/firewall/config"
129 # Remove old configuration
130 rm
-rf
"/var/ipfire/dmzholes"
134 if [ -d
"/var/ipfire/portfw" ]; then
138 # Remove old configuration
139 rm
-rf
"/var/ipfire/portfw"
145 # Convert old OpenVPN CCD files (CN change, Core Update 75)
148 # Snort to suricata converter.
149 if [ -d
"/var/ipfire/snort" ]; then
153 # Remove old configuration directory.
154 rm
-rf
"/var/ipfire/snort"
157 # Convert DNS settings
160 # move nobeeps if exist
161 [ -e
"/var/ipfire/ppp/nobeeps" ] && mv
/var/ipfire
/ppp/nobeeps
/var/ipfire
/red/nobeeps
167 local filelist
=( /var/log/messages* /var
/log/*.log /var/log/**/*.log )
169 echo
"${filelist[@]}"
172 make_addon_backup
() {
176 if [ ! -f
"/var/ipfire/backup/addons/includes/${name}" ]; then
177 echo
"${name} does not have any backup includes" >&2
181 local filename
="/var/ipfire/backup/addons/backup/${name}.ipf"
183 tar cvzf
"${filename}" \
184 $(process_includes
"/var/ipfire/backup/addons/includes/${name}")
187 restore_addon_backup
() {
190 if [ -d
"/tmp/${name}.ipf" ]; then
191 mv
"/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
194 tar xvzpf
"/var/ipfire/backup/addons/backup/${name}.ipf" -C
/
203 local filename
="${1}"
205 if [ -z
"${filename}" ]; then
206 filename
="/var/ipfire/backup/${NOW}.ipf"
209 make_backup
"${filename}" $(find_logfiles
)
213 local filename
="${1}"
215 if [ -z
"${filename}" ]; then
216 filename
="/var/ipfire/backup/${NOW}.ipf"
219 make_backup
"${filename}"
223 local filename
="${1}"
225 if [ -z
"${filename}" ]; then
226 filename
="/tmp/restore.ipf"
229 restore_backup
"/tmp/restore.ipf"
233 make_addon_backup
"$@"
237 restore_addon_backup
"${1/.ipf/}"
241 # Desired backup filename
242 local filename
="/var/ipfire/backup/${NOW}.ipf"
244 if make_backup
"${filename}"; then
245 /usr/local/bin/backupiso
"${NOW}" &
250 mkdir -p
/var/ipfire
/backup/addons
/{backup
,includes
}
254 process_includes
"/var/ipfire/backup/include" "/var/ipfire/backup/include.user"
257 /var/ipfire
/backup/*.ipf
|/var/ipfire
/backup/addon
s/backup/*.ipf|/var
/tmp/backupiso
/*.iso
)
262 echo
"${0}: [include|exclude|restore|addonbackup <addon>|restoreaddon <addon>|iso]" >&2