Luci_app_statistics now has a backup feature starting with 23.05.2

I recently adopted multiple rootfs partitions as a long term x86 sysupgrade strategy. For this use-case, I want to keep the running RRD data in tmpfs, but backed up to a separate data partition, thus allow seamless restores when switching rootfs slots (in typical A/B testing or upgrade scenarios).

  • rootfs A (active)
  • rootfs B (standby)
  • data (to be mounted by rootfs slots)

I made the following patch to support relocating $BACKUP_DIR (with fallback), and if the relocated $BACKUP_DIR can persist a sysupgrade, optionally drop RRD artifacts out of the sysupgrade backup file list.

--- /mnt/sda2/etc/init.d/luci_statistics [original]
+++ /etc/init.d/luci_statistics [modified]
@@ -6,7 +6,9 @@
 STOP=11
 USE_PROCD=1
 
-BACKUP_DIR="/etc/luci_statistics"
+### support relocating $BACKUP_DIR (with fallback)
+BACKUP_DIR=$(uci -q get luci_statistics.collectd_rrdtool.backup_dir)
+BACKUP_DIR=${BACKUP_DIR:-/etc/luci_statistics}
 BACKUP_FILE="${BACKUP_DIR}/rrdbackup.tgz"
 SYSUPGRADE_BACKUP_FILE="${BACKUP_DIR}/rrdbackup.sysupgrade.tgz"
 SYSUPGRADE_BACKUP_TWIN_A="${BACKUP_DIR}/sysupgrade.trustme.txt"
@@ -162,11 +164,15 @@
 			### Copy the backup to use for sysupgrade
 			copy_backup_for_sysupgrade
 		}
-		### Edit the backup file list to remove everything else
-		sed -i -e /${BACKUP_DIR//\//\\/}/d $filelist
-		### Add only the files we need to ensure proper
-		### restore behavior
-		echo ${SYSUPGRADE_BACKUP_FILE} >>$filelist
-		echo ${SYSUPGRADE_BACKUP_TWIN_A} >>$filelist
+		### if the relocated $BACKUP_DIR can persist a sysupgrade,
+		### we can safely drop RRD artifacts from the backup file list.
+		[ -f "$BACKUP_DIR/.safe_for_sysupgrade" ] || {
+			### Edit the backup file list to remove everything else
+			sed -i -e /${BACKUP_DIR//\//\\/}/d $filelist
+			### Add only the files we need to ensure proper
+			### restore behavior
+			echo ${SYSUPGRADE_BACKUP_FILE} >>$filelist
+			echo ${SYSUPGRADE_BACKUP_TWIN_A} >>$filelist
+		}
 	}
 }

I am looking for feedback on my approach. If it is deemed safe and useful for others with the same use-case, I can then submit a PR.