At ConfD startup - how do I detect an upgrade and store my existing pre-upgrade data?

When you for example remove, modify, or add YANG modules (fxs files) CDB will remove all config and operational data that are no longer part of the new CDB schema at startup during upgrade from the old schema to the new schema that was implemented by the YANG modules.

At start-phase0 är it is possible to use CDB API calls to for example fetch data from CDB pre-upgrade, i.e. the way CDB was setup before the upgrade is at start-phase0 still available for applications to read.
This enables applications to for example fetch data and load it into the new schema either as part of the upgrade as an upgrade client or at some later point.

Example using the confd_load and confd_cmd command line tools:

$ confd --start-phase0
          ... Check if an upgrade is about to occur ...
$ confd_cmd -c get_phase
phase: 0 flags: 0x2 UPGRADE
         ... So now we know that an upgrade will occur ...
         ... Here we for example save config and operational data ...
         ... to /tmp/conf.xml ...
$ confd_load -F x > /tmp/conf.xml 
          ... Start other internal daemons ...
$ confd --start-phase1
          ... Reload the CDB schema YANG modules (fxs files) and then ...
$ confd --start-phase2 
          ... In this simple example we restore both config ... 
          ... and operational data after ConfD is up and running ...
$ confd_load -l -F x /tmp/conf.xml