# #
###############################################################################
+shopt -s nullglob
+
NOW="$(date "+%Y-%m-%d-%H:%M")"
list_addons() {
process_includes() {
local include
-
for include in $@; do
local file
while read -r file; do
- for file in ${file}; do
+ # Skip any empty line (which will include /)
+ [ -n "${file}" ] || continue
+
+ for file in /${file}; do
if [ -e "${file}" ]; then
echo "${file}"
fi
done
# Backup using global exclude/include definitions
- tar cvf "${filename}" \
+ tar cvfz "${filename}" -C / \
--exclude-from="/var/ipfire/backup/exclude" \
- $(process_includes "/var/ipfire/backup/include") \
- "$@"
-
- # Backup using user exclude/include definitions and append to global backup
- tar rvf "${filename}" \
--exclude-from="/var/ipfire/backup/exclude.user" \
+ $(process_includes "/var/ipfire/backup/include") \
$(process_includes "/var/ipfire/backup/include.user") \
"$@"
- # gzip the combined global/user backup and use .ipf suffix
- gzip --suffix .ipf "${filename}"
-
return 0
}
restore_backup() {
local filename="${1}"
- tar xvzpf "${filename}" -C /
+ # Extract backup
+ if ! tar xvzpf "${filename}" -C / \
+ --exclude-from="/var/ipfire/backup/exclude" \
+ --exclude-from="/var/ipfire/backup/exclude.user"; then
+ echo "Could not extract backup" >&2
+ return 1
+ fi
# Restart syslogd, httpd and suricata in case we've just loaded old logs
apachectl -k graceful
rm -rf "/var/ipfire/snort"
fi
+ # IDS multiple providers converter.
+ if [ -e "/var/ipfire/suricata/rules-settings" ]; then
+ # Run the converter
+ convert-ids-multiple-providers
+ fi
+
# Convert DNS settings
convert-dns-settings
mv "/tmp/${name}.ipf" "/var/ipfire/backup/addons/backup/${name}.ipf"
fi
- tar xvzpf "/var/ipfire/backup/addons/backup/${name}.ipf" -C /
+ # Extract backup
+ if ! tar xvzpf "/var/ipfire/backup/addons/backup/${name}.ipf" -C /; then
+ echo "Could not extract backup" >&2
+ return 1
+ fi
}
main() {
local filename="${1}"
if [ -z "${filename}" ]; then
- filename="/var/ipfire/backup/${NOW}"
+ filename="/var/ipfire/backup/${NOW}.ipf"
fi
make_backup "${filename}" $(find_logfiles)
local filename="${1}"
if [ -z "${filename}" ]; then
- filename="/var/ipfire/backup/${NOW}"
+ filename="/var/ipfire/backup/${NOW}.ipf"
fi
make_backup "${filename}"
filename="/tmp/restore.ipf"
fi
- restore_backup "/tmp/restore.ipf"
+ restore_backup "${filename}"
;;
addonbackup)
local filename="/var/ipfire/backup/${NOW}.ipf"
if make_backup "${filename}"; then
- /usr/local/bin/backupiso "${NOW}" &
+ /usr/local/bin/backupiso "${NOW}"
fi
;;