$darkmode
Elektra 0.11.0
Recording Changes to the KDB

Elektra provides a powerful session recording feature. You can control it through the kdb command-line utility.

Session recording will track all the changes done to the KDB while it is enabled. This includes changes done by elektrified applications themselves too, not only changes done through the kdb utility. The recorded changes can be exported, undone or used for auditing purposes.

There are seven commands to interact with the session recording feature:

For a more detailed description and options for each command, please take a look at their respective man pages.

A Simple Recording Session

1 # Seed some data first
2 kdb set user:/test/name Franz
3 kdb set user:/test/color Red
4 
5 # Enable session recording for all keys below user:/
6 kdb record-start user:/
7 # RET:0
8 
9 kdb set user:/test/name Hans
10 kdb set user:/test/age 29
11 kdb rm user:/test/color
12 
13 # View the current state of session recording
14 kdb record-state
15 #> Recording is active for user:/⏎⏎Added 1 key(s)⏎Modified 1 key(s)⏎Removed 1 key(s)⏎⏎Added key user:/test/age⏎Modified key user:/test/name⏎Removed key user:/test/color
16 
17 # Stop session recording again
18 kdb record-stop
19 # RET:0

Exporting Recorded changes

One of the most powerful features of session recording is the ability to export the recorded changes. This allows you to apply the specific modifications on other computers, without having to export and overwrite the complete configuration.

1 kdb record-export [<source>] [<format>]

Where source and format are optional parameters. The source parameter lets you specify which keys you want to export. By default, this is all keys, or /. The format parameter lets you specify which format you want to export the changes in. By default, we use the ansible format. Note that the format is just the name of the Elektra storage plugin you want to use.

You can also use the -c option to specify a list of configuration parameters for the storage plugin. See the README of the plugin for more details about which parameters are supported.

1 # Export recorded changes into an Ansible playbook
2 kdb record-export / ansible -c playbook/name="Recording Tutorial"
3 # RET:0
1 ---
2 - name: Recording Tutorial
3  hosts: all
4  collections:
5  - elektra_initiative.libelektra
6  tasks:
7  - name: Set Elektra Keys
8  elektra:
9  keys:
10  - user:
11  test:
12  age:
13  - value: 29
14  color:
15  - remove: true
16  name:
17  - value: Hans