mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-20 06:08:08 +00:00
base-files: sysupgrade: Selectively restore from backups
For users who wish to restore a subset of the backup. Suitable when importing a backup from a different architecture where certain config files would cause problems after reboot. The CONF_SELECTIVE_RESTORE_FILELIST `filelist.txt` content is a simple text file, with one filename per line: ```txt etc/config/file1 etc/config/file2 etc/config/file3 ``` Tested on 23.05.5 Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
parent
e00b6ba0c8
commit
36b35e484a
@ -20,6 +20,8 @@ CONF_IMAGE=
|
|||||||
CONF_BACKUP_LIST=0
|
CONF_BACKUP_LIST=0
|
||||||
CONF_BACKUP=
|
CONF_BACKUP=
|
||||||
CONF_RESTORE=
|
CONF_RESTORE=
|
||||||
|
CONF_SELECTIVE_RESTORE=
|
||||||
|
CONF_SELECTIVE_RESTORE_FILELIST=
|
||||||
NEED_IMAGE=
|
NEED_IMAGE=
|
||||||
HELP=0
|
HELP=0
|
||||||
TEST=0
|
TEST=0
|
||||||
@ -48,6 +50,7 @@ while [ -n "$1" ]; do
|
|||||||
-u) SKIP_UNCHANGED=1;;
|
-u) SKIP_UNCHANGED=1;;
|
||||||
-b|--create-backup) CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
|
-b|--create-backup) CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
|
||||||
-r|--restore-backup) CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
|
-r|--restore-backup) CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
|
||||||
|
-s|--selectively-restore-backup) CONF_SELECTIVE_RESTORE_FILELIST="$2" CONF_SELECTIVE_RESTORE="$3" NEED_IMAGE=1; shift;shift;;
|
||||||
-l|--list-backup) CONF_BACKUP_LIST=1;;
|
-l|--list-backup) CONF_BACKUP_LIST=1;;
|
||||||
-f) CONF_IMAGE="$2"; shift;;
|
-f) CONF_IMAGE="$2"; shift;;
|
||||||
-F|--force) export FORCE=1;;
|
-F|--force) export FORCE=1;;
|
||||||
@ -98,6 +101,11 @@ backup-command:
|
|||||||
restore a .tar.gz created with sysupgrade -b
|
restore a .tar.gz created with sysupgrade -b
|
||||||
then exit. Does not flash an image. If file is '-',
|
then exit. Does not flash an image. If file is '-',
|
||||||
the archive is read from stdin.
|
the archive is read from stdin.
|
||||||
|
-s | --selectively-restore-backup <file-with-list-of-filenames> <file>
|
||||||
|
selectively restore a .tar.gz created with sysupgrade -b
|
||||||
|
by passing a file containing the desired list of filenames,
|
||||||
|
then exit. Does not flash an image. If file is '-',
|
||||||
|
the archive is read from stdin.
|
||||||
-l | --list-backup
|
-l | --list-backup
|
||||||
list the files that would be backed up when calling
|
list the files that would be backed up when calling
|
||||||
sysupgrade -b. Does not create a backup file.
|
sysupgrade -b. Does not create a backup file.
|
||||||
@ -336,6 +344,22 @@ if [ -n "$CONF_RESTORE" ]; then
|
|||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$CONF_SELECTIVE_RESTORE" ]; then
|
||||||
|
if [ "$CONF_SELECTIVE_RESTORE" != "-" ] && [ ! -f "$CONF_SELECTIVE_RESTORE" ]; then
|
||||||
|
echo "Backup archive '$CONF_SELECTIVE_RESTORE' not found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
|
||||||
|
v "Selectively restoring config files..."
|
||||||
|
if [ "$(type -t platform_restore_backup)" = 'platform_restore_backup' ]; then
|
||||||
|
platform_selectively_restore_backup "$TAR_V"
|
||||||
|
else
|
||||||
|
tar -C / -x"${TAR_V}"zf "$CONF_SELECTIVE_RESTORE" -T "$CONF_SELECTIVE_RESTORE_FILELIST"
|
||||||
|
fi
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
type platform_check_image >/dev/null 2>/dev/null || {
|
type platform_check_image >/dev/null 2>/dev/null || {
|
||||||
echo "Firmware upgrade is not implemented for this platform." >&2
|
echo "Firmware upgrade is not implemented for this platform." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -128,3 +128,10 @@ platform_restore_backup() {
|
|||||||
tar -C / -x${TAR_V}zf "$CONF_RESTORE"
|
tar -C / -x${TAR_V}zf "$CONF_RESTORE"
|
||||||
bcm27xx_set_root_part
|
bcm27xx_set_root_part
|
||||||
}
|
}
|
||||||
|
|
||||||
|
platform_selectively_restore_backup() {
|
||||||
|
local TAR_V=$1
|
||||||
|
|
||||||
|
tar -C / -x${TAR_V}zf "$CONF_RESTORE" -T "$CONF_SELECTIVE_RESTORE_FILELIST"
|
||||||
|
bcm27xx_set_root_part
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user