Configuration backup

Overview

StackState configuration can be exported and imported. The import/export functionality can be used to automate the installation process and/or for backup purposes. An export and import can be made in the settings page of StackState's user interface by using the buttons 'Export Model' and 'Import Model'.

Export configuration

An export of the StackState configuration can be obtained from the StackState UI, the StackState CLI or using curl commands. Note that the lock status of configuration items installed by a StackPack configuration will not be included in the export.
To export configuration using the StackState CLI or curl:
StackState CLI
curl
1
# Output in terminal window
2
sts graph export
3
4
# Export to file
5
sts graph export > export.stj
Copied!
1
curl -X POST -H 'Content-Type: application/json;charset=UTF-8' \
2
-d '{}' \
3
"http://<host>:7070/api/export?timeoutSeconds=300" > export.stj
Copied!
To export configuration from the StackState UI:
  1. 1.
    Go to Settings > Import/Export > Export Settings
  2. 2.
    Click on the button STS-EXPORT-ALL.
Export configuration from the StackState UI

Export configuration with authentication (curl)

StackState server can be configured to authenticate users when they access the application. In this case, an export curl script is required to first obtain a token before making the export request. This is not necessary when using the StackState CLI as authentication details are configured during installation.
Here is a sample sequence of curl commands to achieve this. The <token> used for authorization is available on the CLI page in the StackState UI main menu:
curl
1
# Obtain session from cookie AkkaHttpPac4jSession
2
# Obtain token from cookie pac4jCsrfToken
3
curl --fail -v \
4
-H "Authorization: ApiToken <token>" <stackstate-api-endpoint> \
5
-H "Content-Type: application/x-www-form-urlencoded" \
6
"http://<HOST>:7070/loginCallback"
7
8
# Do actual request
9
export SESSION="<MY_SESSION>"; export TOKEN="<MY_TOKEN>"; \
10
curl -v -X POST \
11
-H 'Content-Type: application/json;charset=UTF-8' \
12
-d '{}' \
13
-H Cookie:AkkaHttpPac4jSession=$SESSION \
14
-H X-Sts-Token:$TOKEN \
15
"http://<HOST>:7070/api/export?timeoutSeconds=300" > export.stj
Copied!

Import configuration

Import is intended to be a one-off action - importing multiple times might result in duplicate configuration entries. This behavior applies to importing nodes without any identifier. It is possible to clear StackState's configuration before an import. Note that the lock status of configuration items installed by a StackPack will not be included in configuration export files - all configuration items will be unlocked after import.
To clear the StackState configuration and import from a file using the StackState CLI or curl. The <token> used for authorization with curl is available on the CLI page in the StackState UI main menu:
StackState CLI
curl
1
sts graph import < export.stj
Copied!
1
## Clear StackState configuration
2
curl -X POST -f "http://<HOST>:7071/clear"
3
4
5
## Import without authentication
6
curl -X POST -d @./export.stj \
7
-H 'Content-Type: application/json;charset=UTF-8' \
8
"http://<host>:7070/api/import?timeoutSeconds=15"
9
10
11
## Import with authentication
12
# Obtain session from cookie AkkaHttpPac4jSession
13
# Obtain token from cookie pac4jCsrfToken
14
curl --fail -v \
15
-H "Authorization: ApiToken <token>" <stackstate-api-endpoint> \
16
-H "Content-Type: application/x-www-form-urlencoded" \
17
"http://<host>:7070/loginCallback"
18
19
# Do actual request
20
export SESSION="<MY_SESSION>"; export TOKEN="<MY_TOKEN>"; \
21
curl -X POST -d @export.stj \
22
-H 'Content-Type: application/json;charset=UTF-8' \
23
-H Cookie:AkkaHttpPac4jSession=$SESSION \
24
-H X-Sts-Token:$TOKEN "http://<HOST>:7070/api/import?timeoutSeconds=15"
Copied!
Alternatively, in the StackState UI:
  1. 1.
    Go to Settings > Import/Export > Import Settings.
  2. 2.
    Choose the *.stj file that you want to import configuration from.
  3. 3.
    Click on the button START IMPORT.
Import configuration from the StackState UI

Import or export individual configuration items

It is possible to export and import individual configuration items through the StackState user interface. For example, to export or export a component type:
  1. 1.
    Go to the Settings page and click on Component Types.
  2. 2.
    To export an individual component type, click on Export as config.
  3. 3.
    To import a configuration item, click on Import Model.

Idempotent import/export

There is a way to use identifiers and namespaces that come with them to perform a configuration update of the specific sets of nodes idempotently. This approach does not lead to duplicates, but checks for the changes within a specified namespace and applies them to existing nodes, including removing nodes, as well as allow for creating the new ones.
Node identifiers are specified in a following pattern: urn:stackpack:{stackpack_name}:{type_name}:{object_name}. The namespace effectively used by this process is urn:stackpack:{stackpack_name}:. If every configuration node has an identifier and they are all in the same namespace, then you can perform an idempotent update using following STS CLI commands:
For export: sts graph export --namespace urn:stackpack:{stackpack_name}:
For import currently we have a curl way: curl -XPOST http://yourInstance/api/import?namespace=urn:stackpack:{stackpack_name} --data @./filename -H 'Content-Type: application/json'

Configuration Export Versioning

As StackState evolves versioning of the exported Node elements is necessary. The export conf contains metadata stating the Node version (_version) which is useful in order to allow an autoupgrade to a more recent version of StackState and ensure compatibility.
1
{
2
"_version": "1.0.0",
3
"timestamp": "2018-12-06T12:30:44.148Z[Etc/UTC]",
4
"nodes": [
5
{
6
"_type": "CheckFunction",
7
"name": "Metric fixed run state",
8
"returnTypes": [
9
"RUN_STATE"
10
],
11
"description": "This check will always return the run state that is provided when a metric has been received.",
12
"id": -196,
13
"script": "return metricFixedRunState;",
14
"parameters": [
15
{
16
"_type": "Parameter",
17
"name": "metrics",
18
"system": false,
19
"id": -194,
20
"multiple": false,
21
"type": "METRIC_STREAM",
22
"required": true
23
},
24
{
25
"_type": "Parameter",
26
"name": "metricFixedRunState",
27
"system": false,
28
"id": -195,
29
"multiple": false,
30
"type": "RUN_STATE_VALUE",
31
"required": true
32
}
33
]
34
}
35
]
36
}
Copied!

Supported Configuration Export version

A configuration export is supported by versions of StackState that are equal or higher than the export's version and with the same major version (see semver). The first configuration export version is 1.0.0, and effectively any Node payload with a version below or missing the version field (_version) will be interpreted and auto-upgraded to version 1.0.0.

For example:

Configuration export version 1.0.0 was introduced in StackState version 1.14.0 Later configuration export version 1.1.0 was introduced in StackState version 1.14.1 Later configuration export version 2.0.0 was introduced in StackState version 1.15.0
This means that Nodes with Configuration version 1.0.0 will work on both StackState 1.14.0 and 1.14.1 but not in 1.15.0 as a major configuration export version (2.0.0) was introduced. As well it means that configuration export version 1.1.0 can only be used from StackState version 1.14.1 but not before as in 1.14.0

Configuration export versions

The table below displays configuration export versions version and on which StackState versions they were introduced.
Configuration Export version
Introduced on StackState version
1.0.0
1.14.0
Last modified 1mo ago