Add S02restorebackups

This commit is contained in:
Calin Crisan 2019-02-02 02:13:31 +02:00
parent 89c7c36a23
commit f22639dcc2
4 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
#!/bin/bash
BACKUPS_DIR="/boot"
BACKUP_PATTERN="backup-*.tar.gz"
DATA_DIR="/data"
test -n "${OS_VERSION}" || source /etc/init.d/base
case "$1" in
start)
if ! ls ${BACKUPS_DIR}/${BACKUP_PATTERN} &>/dev/null; then
exit; # no backups
fi
mount -o remount,rw /boot
for file in ${BACKUPS_DIR}/${BACKUP_PATTERN}; do
msg_begin "Restoring backup from $(basename ${file})"
tar -mxf ${file} -C ${DATA_DIR}
if [[ $? == 0 ]]; then
rm ${file}
msg_done
else
msg_fail
fi
done
# source os_conf again, as it might have changed after restore
test -f /etc/init.d/os_conf && source /etc/init.d/os_conf
if [[ "${OS_DEBUG}" != "true" ]]; then
mount -o remount,ro /boot
fi
;;
stop)
true
;;
*)
echo "Usage: $0 {start}"
exit 1
esac
exit $?