[OpenWrt-Devel,v2,2/4] base-files: add sysupgrade -u to skip unchanged files

Message ID 20180404232826.10815-3-luizluca@gmail.com
State New
Headers show
Series
  • base-files: add new backup options
Related show

Commit Message

Luiz Angelo Daros de Luca April 4, 2018, 11:28 p.m.
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 <luizluca@gmail.com>
---
 package/base-files/files/sbin/sysupgrade | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

Comments

Stefan Lippers-Hollmann April 7, 2018, 10:19 p.m. | #1
Hi

On 2018-04-04, Luiz Angelo Daros de Luca wrote:
> 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 April 8, 2018, 6:03 a.m. | #2
> 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
             luizluca@gmail.com

Patch

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() {