be more careful when dumping sysrepo configuration
I've seen one lab device with a zero-size JSON file, which obviously
cannot be restored. That's fishy and this should not happen, so let's
try to be a bit more robust when creating that file:
- do not overwrite in place (which might hit a FS race and cause an
empty file)
- check that sysrepocfg produced "some data" (if it crashed early
enough, it would previously still have been an empty file due to the
output redirection)
The actual writeout is a bit more involved than I would prefer, and
because I want locking (thanks, Tomas), I think it's easier to use two
scripts for this one.
Change-Id: I43fccd3a49cae77f88b282ccac07471453910c25
diff --git a/package/czechlight-cfg-fs/impl-cfg-save-sysrepo b/package/czechlight-cfg-fs/impl-cfg-save-sysrepo
new file mode 100644
index 0000000..385503f
--- /dev/null
+++ b/package/czechlight-cfg-fs/impl-cfg-save-sysrepo
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+CONFIG_FILE=/cfg/sysrepo/startup.json
+NEW_COPY=/cfg/sysrepo/startup.json.2
+
+sysrepocfg -d startup -f json -X > ${NEW_COPY}
+if [ ! -s ${NEW_COPY} ]; then
+ logger -p user.emerg "Corrupted sysrepo configuration dump"
+ exit 1
+fi
+sync ${NEW_COPY}
+mv ${NEW_COPY} ${CONFIG_FILE}
+sync ${CONFIG_FILE}