WildFly: How to rollback CLI changes

In this short article we will learn how to rollback WildFly Command Line commands after their execution in order to restore the original XML configuration.

WildFly Configuration History

The key concept is that WildFly uses the JBOSS_HOME/standalone/configuration/standalone_xml_history folder to store configuration changes.

Within this folder you will find the current configuration history, the configuration history by day and the snapshot folder:

├── 20221119-180044147
│   ├── standalone-full.v1.xml
│   ├── standalone-full.v2.xml
│   ├── standalone-full.v3.xml
│   ├── standalone-full.v4.xml
│   ├── standalone-full.v5.xml
│   ├── standalone-full.v6.xml
│   ├── standalone-full.v7.xml
│   ├── standalone-full.v8.xml
│   └── standalone-full.v9.xml
├── current
├── snapshot
│   ├── savepointstandalone-full.xml
│   └── savepointstandalone.xml

The folder we are interested in is the snapshot folder. Within this directory, you will find all the XML configuration snapshot you are taking from the CLI. In order to take a configuration snapshot, you can use the :take-snapshot comand:

    "outcome" => "success",
    "result" => "/home/jboss/wildfly-27.0.0.Final/standalone/configuration/standalone_xml_history/snapshot/20221119-180842683standalone-

As you can see, when you use it without any parameter, an XML configuration snapshot will be saved in a file which contains the Timestamp and the configuration being used.

So how do I restore configuration changes with the CLI ?

There are two ways to restore the XML configuration after changes. You can simply overwrite the XML configuration with the snapshot:

cp $JBOSS_HOME/standalone/configuration/standalone_xml_history/snapshot/<snapshot-name> cp $JBOSS_HOME/standalone/configuration/standalone.xml

Overwriting the XMl configuration when the server is running is a bad practice that can result in configuration loss. Therefore, the above procedure requires you a server stop and start.

You can however rollback changes on an active server as well. The trick is to use a name for your snapshot. For example:

    "outcome" => "success",
    "result" => "/home/jboss/wildfly-27.0.0.Final/standalone/configuration/standalone_xml_history/snapshot/savepointstandalone-full-ha.xml"

Next, you can apply changes to your configuration. Finally, to rollback all changes you can use the reload command passing as server-config the snapshot. For example:

:reload (server-config=standalone_xml_history/snapshot/savepointstandalone-full-ha.xml)

This way, you can restore the snapshot configuration without a server restart.

NOTE: Even though a snapshot is able to incorporate all configuration changes, it will not rollback changes you have made to the modules directory filesystem.

Therefore, you should either manually delete the modules from the JBOSS_HOME/modules/yourmodules PATH or use the CLI module remove command:

module remove --name=com.mymodule