Discussion:
[OpenWrt-Devel] [PATCH v2 0/4] [RFC] base-files: add new backup options
Luiz Angelo Daros de Luca
2018-04-04 23:28:22 UTC
Permalink
My previous patch on Nov2017 (http://lists.infradead.org/pipermail/lede-dev/2017-November/009892.html)
generated some discussion because it depends on the presence of /rom to become
effetive. So I opted to turn it into a new sysupgrade option (-u).

Besides that, I added some more stuff to sysupgrade that I use in
my systems.

Each patch in this series is almost indepenly of each other.
Except for the first one, they add new sysupgrade options:

-u) equivalent to the previous patch. I think that, if adopted as
default in future, it will make upgrades cleaner. For now, it
is optional.

-o) this option tries to save everything that was changed. It includes
all new files, conffiles (works with -u), sysupgrade.conf and
keep.d. This is what I normally use in my backups as it saves both data
and confs, keeping them as clean as possible.

-k) This adds a new file that I use to quickly reinstall all extra
packages. A future improvement would be to use it in a service that installs
install those packages as soon as network is up (similar to uci-default
scripts)

For now, it is still pending to bump package release.

--
Luiz Angelo
Luiz Angelo Daros de Luca
2018-04-04 23:28:23 UTC
Permalink
Renamed add_uci_conffiles to add_conffiles as it includes
any conffiles listed, not only UCI ones.

Make do_save_conffiles arg mandatory

Allow other options after -l (like -c)

Signed-off-by: Luiz Angelo Daros de Luca <***@gmail.com>
---
package/base-files/files/sbin/sysupgrade | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index bf5428af25..46e46c3342 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -30,7 +30,7 @@ while [ -n "$1" ]; do
-p) export SAVE_PARTITIONS=0;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
- -l|--list-backup) export CONF_BACKUP_LIST=1; break;;
+ -l|--list-backup) export CONF_BACKUP_LIST=1;;
-f) export CONF_IMAGE="$2"; shift;;
-F|--force) export FORCE=1;;
-T|--test) export TEST=1;;
@@ -49,10 +49,10 @@ export CONF_TAR=/tmp/sysupgrade.tgz

IMAGE="$1"

-[ -z "$IMAGE" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
+[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && {
cat <<EOF
Usage: $0 [<upgrade-option>...] <image file or URL>
- $0 [-q] [-i] <backup-command> <file>
+ $0 [-q] [-i] [-c] <backup-command> <file>

upgrade-option:
-f <config> restore configuration from .tar.gz (file or url)
@@ -115,7 +115,7 @@ list_changed_conffiles() {
done
}

-add_uci_conffiles() {
+add_conffiles() {
local file="$1"
( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
@@ -131,6 +131,7 @@ add_overlayfiles() {
-e '\,/META_[a-zA-Z0-9]*$,d' \
-e '\,/functions.sh$,d' \
-e '\,/[^/]*-opkg$,d' \
+ -e '\,/etc/urandom.seed$,d' \
"$file"
return 0
}
@@ -146,13 +147,13 @@ if [ $SAVE_OVERLAY = 1 ]; then
}
sysupgrade_init_conffiles="add_overlayfiles"
else
- sysupgrade_init_conffiles="add_uci_conffiles"
+ sysupgrade_init_conffiles="add_conffiles"
fi

include /lib/upgrade

do_save_conffiles() {
- local conf_tar="${1:-$CONF_TAR}"
+ local conf_tar="$1"

[ -z "$(rootfs_type)" ] && {
echo "Cannot save config while running from ramdisk."
@@ -247,7 +248,7 @@ if [ -n "$CONF_IMAGE" ]; then
get_image "$CONF_IMAGE" "cat" > "$CONF_TAR"
export SAVE_CONFIG=1
elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
- [ $TEST -eq 1 ] || do_save_conffiles
+ [ $TEST -eq 1 ] || do_save_conffiles "$CONF_TAR"
export SAVE_CONFIG=1
else
[ $TEST -eq 1 ] || rm -f "$CONF_TAR"
--
2.16.3
Luiz Angelo Daros de Luca
2018-04-04 23:28:24 UTC
Permalink
With '-u', for a file /aaa/bbb/ccc enlisted for backup,
it will only get into backup if /rom/aaa/bbb/ccc does not
exist or /aaa/bbb/ccc is different from /rom/aaa/bbb/ccc.

It also works with '-c', but only effective for files touched
but not modified.

Signed-off-by: Luiz Angelo Daros de Luca <***@gmail.com>
---
package/base-files/files/sbin/sysupgrade | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 46e46c3342..4d221ef5d6 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -10,6 +10,7 @@ export VERBOSE=1
export SAVE_CONFIG=1
export SAVE_OVERLAY=0
export SAVE_PARTITIONS=1
+export SKIP_UNCHANGED=0
export CONF_IMAGE=
export CONF_BACKUP_LIST=0
export CONF_BACKUP=
@@ -28,6 +29,7 @@ while [ -n "$1" ]; do
-n) export SAVE_CONFIG=0;;
-c) export SAVE_OVERLAY=1;;
-p) export SAVE_PARTITIONS=0;;
+ -u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
-l|--list-backup) export CONF_BACKUP_LIST=1;;
@@ -52,12 +54,13 @@ IMAGE="$1"
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -a $CONF_BACKUP_LIST -eq 0 -o $HELP -gt 0 ] && {
cat <<EOF
Usage: $0 [<upgrade-option>...] <image file or URL>
- $0 [-q] [-i] [-c] <backup-command> <file>
+ $0 [-q] [-i] [-c] [-u] <backup-command> <file>

upgrade-option:
-f <config> restore configuration from .tar.gz (file or url)
-i interactive mode
-c attempt to preserve all changed files in /etc/
+ -u skip from backup files that are equals to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
-T | --test
@@ -119,20 +122,19 @@ add_conffiles() {
local file="$1"
( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
- -type f -o -type l 2>/dev/null;
+ \( -type f -o -type l \) $find_filter 2>/dev/null;
list_changed_conffiles ) | sort -u > "$file"
return 0
}

add_overlayfiles() {
local file="$1"
- find /overlay/upper/etc/ -type f -o -type l | sed \
- -e 's,^/overlay\/upper/,/,' \
- -e '\,/META_[a-zA-Z0-9]*$,d' \
- -e '\,/functions.sh$,d' \
+ ( cd /overlay/upper/; find ./etc \( -type f -o -type l \) $find_filter | sed \
+ -e 's,^\.,,' \
+ -e '\,^/etc/board.json$,d' \
-e '\,/[^/]*-opkg$,d' \
- -e '\,/etc/urandom.seed$,d' \
- > "$file"
+ -e '\,^/etc/urandom.seed$,d' \
+ )> "$file"
return 0
}

@@ -150,6 +152,15 @@ else
sysupgrade_init_conffiles="add_conffiles"
fi

+find_filter=""
+if [ $SKIP_UNCHANGED = 1 ]; then
+ [ ! -d /rom/ ] && {
+ echo "'/rom/' is required by '-u'"
+ exit 1
+ }
+ find_filter='( ( -exec test -e /rom/{} ; -exec cmp -s /{} /rom/{} ; ) -o -print )'
+fi
+
include /lib/upgrade

do_save_conffiles() {
--
2.16.3
Stefan Lippers-Hollmann
2018-04-07 22:19:07 UTC
Permalink
Hi
Post by Luiz Angelo Daros de Luca
With '-u', for a file /aaa/bbb/ccc enlisted for backup,
it will only get into backup if /rom/aaa/bbb/ccc does not
exist or /aaa/bbb/ccc is different from /rom/aaa/bbb/ccc.
It also works with '-c', but only effective for files touched
but not modified.
[...]

This patch series works very nicely for me on ar71xx, brcm47xx, ipq806x
and lantiq, -u unclutters the overlay contents quite significantly and
makes spotting (manual) changes a lot easier.

Thanks
Stefan Lippers-Hollmann
Luiz Angelo Daros de Luca
2018-04-08 06:03:43 UTC
Permalink
Post by Stefan Lippers-Hollmann
This patch series works very nicely for me on ar71xx, brcm47xx, ipq806x
and lantiq, -u unclutters the overlay contents quite significantly and
makes spotting (manual) changes a lot easier.
Thanks Stefan for the feedback. If you want to simply spot changes, I would
recommend '-o -l'.
I normally use '-o -u -k -b mybkp.tgz'.

I use backup like these for years and since last year I'm trying to share
it to everybody. It has already saved me several hours.

For those that want to keep track, I'm using this branch for it:

https://github.com/luizluca/openwrt/raw/better-backups-v2/package/base-files/files/sbin/sysupgrade

It already has some minor fixes on top of sent patches.

And for those that simply want to test it (or use it):

$ wget -O /sbin/sysupgrade.alt
https://raw.githubusercontent.com/luizluca/openwrt/better-backups-v2/package/base-files/files/sbin/sysupgrade
$ chmod +x /sbin/sysupgrade.alt

It's a shame githubusercontent.com forces https.

It is safe to use this "standalone version" even on LEDE 17.01.x for
creating backups (-b) as all used code is in sysupgrade itself.
However, I still use unchanged sysupgrade for flashing (passing the backup
archive using -f). Flashing depends on external files (/lib/upgrade)
whose changes might also depend on a sysupgrade change.

Regards,

---
Luiz Angelo Daros de Luca
***@gmail.com
Luiz Angelo Daros de Luca
2018-04-04 23:28:25 UTC
Permalink
Add sysupgrade '-o' option in order to include all overlay files in
backup, except for those that are from packages but including files
listed in conffiles, sysupgrade.conf or /lib/upgrade/keep.d.

With '-u' option, it will skip files equals to /rom and conffiles that
were not changed.

Signed-off-by: Luiz Angelo Daros de Luca <***@gmail.com>
---
package/base-files/files/sbin/sysupgrade | 46 +++++++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 4d221ef5d6..01a942bac6 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -9,6 +9,7 @@ export INTERACTIVE=0
export VERBOSE=1
export SAVE_CONFIG=1
export SAVE_OVERLAY=0
+export SAVE_OVERLAY_PATH=
export SAVE_PARTITIONS=1
export SKIP_UNCHANGED=0
export CONF_IMAGE=
@@ -27,7 +28,8 @@ while [ -n "$1" ]; do
-v) export VERBOSE="$(($VERBOSE + 1))";;
-q) export VERBOSE="$(($VERBOSE - 1))";;
-n) export SAVE_CONFIG=0;;
- -c) export SAVE_OVERLAY=1;;
+ -c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
+ -o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
@@ -60,6 +62,8 @@ upgrade-option:
-f <config> restore configuration from .tar.gz (file or url)
-i interactive mode
-c attempt to preserve all changed files in /etc/
+ -o attempt to preserve all changed files in /, exept those
+ from packages but including changed confs.
-u skip from backup files that are equals to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
@@ -129,12 +133,48 @@ add_conffiles() {

add_overlayfiles() {
local file="$1"
- ( cd /overlay/upper/; find ./etc \( -type f -o -type l \) $find_filter | sed \
+
+ local packagesfiles=$1.packagesfiles
+ touch "$packagesfiles"
+
+ if [ "$SAVE_OVERLAY_PATH" = / ]; then
+ local conffiles=$1.conffiles
+ local keepfiles=$1.keepfiles
+
+ list_conffiles | cut -f2 -d ' ' | sort -u > "$conffiles"
+
+ # backup files from /etc/sysupgrade.conf and /lib/upgrade/keep.d, but
+ # ignore those aready controlled by opkg conffiles
+ find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
+ /etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
+ \( -type f -o -type l \) 2>/dev/null | sort -u |
+ grep -h -v -x -F -f $conffiles > "$keepfiles"
+
+ # backup conffiles, but only those changed if '-u'
+ [ $SKIP_UNCHANGED = 1 ] &&
+ list_changed_conffiles | sort -u > "$conffiles"
+
+ # do not backup files from packages, except those listed
+ # in conffiles and keep.d
+ find /usr/lib/opkg/info -type f -name "*.list" | sort -u |
+ xargs -r grep -h -v -x -F -f $conffiles |
+ grep -v -x -F -f $keepfiles > "$packagesfiles"
+ rm -f "$keepfiles" "$conffiles"
+ fi
+
+ # busybox grep bug when file is empty
+ [ -s "$packagesfiles" ] || echo > $packagesfiles
+
+ ( cd /overlay/upper/; find .$SAVE_OVERLAY_PATH \( -type f -o -type l \) $find_filter | sed \
-e 's,^\.,,' \
-e '\,^/etc/board.json$,d' \
-e '\,/[^/]*-opkg$,d' \
-e '\,^/etc/urandom.seed$,d' \
- )> "$file"
+ -e '\,^/usr/lib/opkg/.*,d' \
+ ) | grep -v -x -F -f $packagesfiles > "$file"
+
+ rm -f "$packagesfiles"
+
return 0
}
--
2.16.3
Luiz Angelo Daros de Luca
2018-04-04 23:28:26 UTC
Permalink
When '-k' is used, sysupgrade inserts into backup a new file
/etc/sysupgrade.installed which contains pkgname and
origin (rom, overlay, unknown).

It's maily used to reinstall all extra packages:

# opkg update
# grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install
# rm etc/sysupgrade.installed

Signed-off-by: Luiz Angelo Daros de Luca <***@gmail.com>
---
package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 01a942bac6..c5067a757b 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -11,6 +11,7 @@ export SAVE_CONFIG=1
export SAVE_OVERLAY=0
export SAVE_OVERLAY_PATH=
export SAVE_PARTITIONS=1
+export SAVE_INSTALLED_PKGS=0
export SKIP_UNCHANGED=0
export CONF_IMAGE=
export CONF_BACKUP_LIST=0
@@ -31,6 +32,7 @@ while [ -n "$1" ]; do
-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
+ -k) export SAVE_INSTALLED_PKGS=1;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
@@ -50,6 +52,7 @@ done

export CONFFILES=/tmp/sysupgrade.conffiles
export CONF_TAR=/tmp/sysupgrade.tgz
+export INSTALLED_PACKAGES=/etc/sysupgrade.installed

IMAGE="$1"

@@ -67,6 +70,8 @@ upgrade-option:
-u skip from backup files that are equals to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
+ -k include in backup a list of current installed packages at
+ $INSTALLED_PACKAGES
-T | --test
Verify image and config .tar.gz but do not actually flash.
-F | --force
@@ -203,6 +208,15 @@ fi

include /lib/upgrade

+targz_append() {
+ local tar="$1"
+ local append_tar="$2"
+ ( gunzip -c "$tar" | head -c -1024;
+ gunzip -c $append_tar
+ ) | gzip > $tar.new
+ mv -f $tar.new $tar
+}
+
do_save_conffiles() {
local conf_tar="$1"

@@ -219,6 +233,22 @@ do_save_conffiles() {
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null

+ if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
+ mkdir -p /tmp/etc
+ cd /tmp/
+
+ # Format: pkg-name<TAB>{rom,overlay,unkown}
+ # rom is used for pkgs in /rom, even if updated later
+ find /usr/lib/opkg/info -name "*.control" \( \
+ \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
+ \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
+ \( -exec echo {} unknown \; \) \
+ \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES:1}
+
+ tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+ targz_append "$conf_tar" sysupgrade.installed.packages.tgz
+ rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+ fi
rm -f "$CONFFILES"
}
--
2.16.3
Philip Prindeville
2018-04-21 01:00:03 UTC
Permalink
Inline
Post by Luiz Angelo Daros de Luca
When '-k' is used, sysupgrade inserts into backup a new file
/etc/sysupgrade.installed which contains pkgname and
origin (rom, overlay, unknown).
# opkg update
# grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install
# rm etc/sysupgrade.installed
---
package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 01a942bac6..c5067a757b 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -11,6 +11,7 @@ export SAVE_CONFIG=1
export SAVE_OVERLAY=0
export SAVE_OVERLAY_PATH=
export SAVE_PARTITIONS=1
+export SAVE_INSTALLED_PKGS=0
export SKIP_UNCHANGED=0
export CONF_IMAGE=
export CONF_BACKUP_LIST=0
@@ -31,6 +32,7 @@ while [ -n "$1" ]; do
-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
+ -k) export SAVE_INSTALLED_PKGS=1;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
@@ -50,6 +52,7 @@ done
export CONFFILES=/tmp/sysupgrade.conffiles
export CONF_TAR=/tmp/sysupgrade.tgz
+export INSTALLED_PACKAGES=/etc/sysupgrade.installed
IMAGE="$1"
-u skip from backup files that are equals to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
+ -k include in backup a list of current installed packages at
+ $INSTALLED_PACKAGES
-T | --test
Verify image and config .tar.gz but do not actually flash.
-F | --force
@@ -203,6 +208,15 @@ fi
include /lib/upgrade
+targz_append() {
+ local tar="$1"
+ local append_tar="$2"
+ ( gunzip -c "$tar" | head -c -1024;
+ gunzip -c $append_tar
+ ) | gzip > $tar.new
This seems a bit fragile
 Isn’t there a better way to do this?
Post by Luiz Angelo Daros de Luca
+ mv -f $tar.new $tar
+}
+
do_save_conffiles() {
local conf_tar="$1"
@@ -219,6 +233,22 @@ do_save_conffiles() {
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
+ if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
+ mkdir -p /tmp/etc
+ cd /tmp/
+
+ # Format: pkg-name<TAB>{rom,overlay,unkown}
+ # rom is used for pkgs in /rom, even if updated later
+ find /usr/lib/opkg/info -name "*.control" \( \
+ \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
+ \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
+ \( -exec echo {} unknown \; \) \
+ \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES:1}
+
+ tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+ targz_append "$conf_tar" sysupgrade.installed.packages.tgz
+ rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+ fi
rm -f "$CONFFILES"
}
--
2.16.3
Philip Prindeville
2018-04-21 01:01:19 UTC
Permalink
Inline
Post by Luiz Angelo Daros de Luca
When '-k' is used, sysupgrade inserts into backup a new file
/etc/sysupgrade.installed which contains pkgname and
origin (rom, overlay, unknown).
# opkg update
# grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install
# rm etc/sysupgrade.installed
---
package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 01a942bac6..c5067a757b 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -11,6 +11,7 @@ export SAVE_CONFIG=1
export SAVE_OVERLAY=0
export SAVE_OVERLAY_PATH=
export SAVE_PARTITIONS=1
+export SAVE_INSTALLED_PKGS=0
export SKIP_UNCHANGED=0
export CONF_IMAGE=
export CONF_BACKUP_LIST=0
@@ -31,6 +32,7 @@ while [ -n "$1" ]; do
-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
-p) export SAVE_PARTITIONS=0;;
+ -k) export SAVE_INSTALLED_PKGS=1;;
-u) export SKIP_UNCHANGED=1;;
-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
@@ -50,6 +52,7 @@ done
export CONFFILES=/tmp/sysupgrade.conffiles
export CONF_TAR=/tmp/sysupgrade.tgz
+export INSTALLED_PACKAGES=/etc/sysupgrade.installed
IMAGE="$1"
-u skip from backup files that are equals to those in /rom
-n do not save configuration over reflash
-p do not attempt to restore the partition table after flash.
+ -k include in backup a list of current installed packages at
+ $INSTALLED_PACKAGES
-T | --test
Verify image and config .tar.gz but do not actually flash.
-F | --force
@@ -203,6 +208,15 @@ fi
include /lib/upgrade
+targz_append() {
+ local tar="$1"
+ local append_tar="$2"
+ ( gunzip -c "$tar" | head -c -1024;
+ gunzip -c $append_tar
+ ) | gzip > $tar.new
This seems a bit fragile… Isn’t there a better way to do this?
Post by Luiz Angelo Daros de Luca
+ mv -f $tar.new $tar
+}
+
do_save_conffiles() {
local conf_tar="$1"
@@ -219,6 +233,22 @@ do_save_conffiles() {
[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
+ if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
+ mkdir -p /tmp/etc
+ cd /tmp/
+
+ # Format: pkg-name<TAB>{rom,overlay,unkown}
+ # rom is used for pkgs in /rom, even if updated later
+ find /usr/lib/opkg/info -name "*.control" \( \
+ \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
+ \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
+ \( -exec echo {} unknown \; \) \
+ \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES:1}
+
+ tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+ targz_append "$conf_tar" sysupgrade.installed.packages.tgz
+ rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+ fi
rm -f "$CONFFILES"
}
--
2.16.3
Loading...