Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Announcement: Try the Ask AI chatbot for answers to your technical questions about Juniper products and solutions.

close
external-header-nav
keyboard_arrow_up
close
keyboard_arrow_left
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

Retrieve a Previous (Rollback) Configuration Using the Junos XML Protocol

date_range 14-Jul-21

In a Junos XML protocol session with a device running Junos OS, a client application can request a previously committed (rollback) configuration. The client can retrieve the configuration by referencing the configuration’s rollback index or its configuration revision identifier.

How to Retrieve a Configuration Using the Rollback Number

In a Junos XML protocol session with a device running Junos OS, to request a previously committed (rollback) configuration, a client application executes the <get-rollback-information> RPC with the <rollback> element. This operation is equivalent to the show system rollback operational mode command. The <rollback> element specifies the rollback index of the previous configuration to display; its value can be from 0 (zero, for the most recently committed configuration) through one less than the number of stored previous configurations (maximum is 49).

To request Junos XML-tagged output, which is the default, the application either includes the <format> element with the value xml or omits the <format> element.

content_copy zoom_out_map
<rpc>
    <get-rollback-information>
        <rollback>index-number</rollback> 
    </get-rollback-information>
</rpc>

The Junos XML protocol server encloses its response in <rpc-reply>, <rollback-information>, and <configuration> tag elements. The <load-success/> tag is a side effect of the implementation and does not affect the results. For information about the attributes in the opening <configuration> tag, see Specifying the Source for Configuration Information Requests in a Junos XML Protocol Session.

content_copy zoom_out_map
<rpc-reply xmlns:junos="URL">
    <rollback-information>
        <load-success/>
        <configuration attributes>
            <!-- tag elements for the complete previous configuration -->
         </configuration>
    </rollback-information>
</rpc-reply>

To request formatted ASCII output, the application includes the <format> element with the value text.

content_copy zoom_out_map
<rpc>
    <get-rollback-information>
        <rollback>index-number</rollback> 
        <format>text</format>
    </get-rollback-information>
</rpc>

The Junos XML protocol server encloses its response in <rpc-reply>, <rollback-information>, <configuration-information>, and <configuration-output> tag elements. For more information about the formatted ASCII notation used in Junos OS configuration statements, see Specifying the Output Format for Configuration Data in a Junos XML Protocol Session.

content_copy zoom_out_map
<rpc-reply xmlns:junos="URL">
    <rollback-information>
        <load-success/>
        <configuration-information>
            <configuration-output>
                <!-- formatted ASCII text for the complete previous configuration -->
            </configuration-output>
        </configuration-information>
    </rollback-information>
</rpc-reply>

Starting in Junos OS Release 16.1, to request a previously committed (rollback) configuration in JSON format, the application includes the <format> element with the value json in the <get-rollback-information> element. Prior to Junos OS Release 16.1, JSON-formatted data is requested by including the format="json" attribute in the opening <get-rollback-information> tag.

content_copy zoom_out_map
<rpc>
    <get-rollback-information>
        <rollback>index-number</rollback> 
        <format>json</format>
    </get-rollback-information>
</rpc>

When you use the format="json" attribute to specify the format, the Junos XML protocol server encloses its response in an <rpc-reply> element, the field name for the top-level JSON member is "rollback-information", and the emitted configuration data uses an older implementation for serialization. When you use the <format>json</format> element to request JSON-formatted data, the Junos XML protocol server encloses its response in <rpc-reply>, <rollback-information>, <configuration-information>, and <json-output> tag elements, the field name for the top-level JSON member is "configuration", and the emitted configuration data uses a newer implementation for serialization.

content_copy zoom_out_map
<rpc-reply xmlns:junos="URL">
    <rollback-information>
        <load-success/>
        <configuration-information>
            <json-output>
                <!-- JSON data for the complete previous configuration -->
            </json-output>
        </configuration-information>
    </rollback-information>
</rpc-reply>

The following example shows how to request Junos XML-tagged output for the rollback configuration that has an index of 2. In actual output, the JUNOS-version variable is replaced by a value such as 20.4R1 for the initial version of Junos OS Release 20.4.

How to Retrieve a Configuration Using the Configuration Revision Identifier

When you successfully commit a configuration, Junos OS assigns that configuration a unique configuration revision identifier. Whereas the rollback index for a previously committed configuration increments with each commit, the configuration revision identifier remains static for the same configuration.

Starting in Junos OS Release 20.4R1, a Junos XML protocol client application can use the <get-configuration-by-revision> RPC to retrieve the configuration corresponding to a given configuration revision identifier. For example:

content_copy zoom_out_map
<rpc>
   <get-configuration-by-revision>
       <revision-string>re0-1605226203-331</revision-string>
   </get-configuration-by-revision>
</rpc>

The server returns the requested configuration enclosed in the <configuration-revision-information> element.

content_copy zoom_out_map
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.4R1/junos">
<configuration-revision-information>
<load-success/>
<configuration junos:changed-seconds="1605226201" junos:changed-localtime="2020-11-12 16:10:01 PST">
...
</configuration>
</configuration-revision-information>
</rpc-reply>

By default, the <get-configuration-by-revision> RPC returns the configuration in XML format. To return the configuration as text or JSON, include the <format> element in the RPC and specify text or json.

content_copy zoom_out_map
<rpc>
    <get-configuration-by-revision>
        <revision-string>re0-1605226203-331</revision-string>
        <format>text</format>
    </get-configuration-by-revision>
</rpc>
content_copy zoom_out_map
<rpc>
    <get-configuration-by-revision>
        <revision-string>re0-1605226203-331</revision-string>
        <format>json</format>
    </get-configuration-by-revision>
</rpc>

You can determine the mapping between a configuration revision identifier and the current rollback index for a particular configuration. Remember that the configuration revision identifier for a given committed configuration is static whereas the rollback index increments with each commit.

To determine the rollback number corresponding to a specific configuration revision identifier, execute the <get-configuration-by-revision> RPC, specify the revision identifier, and include the empty <rollback-number/> tag.

content_copy zoom_out_map
<rpc>
   <get-configuration-by-revision>
       <revision-string>re0-1605226203-331</revision-string>
       <rollback-number/>
   </get-configuration-by-revision>
</rpc>

The device returns the rollback index currently associated with that configuration revision identifier.

content_copy zoom_out_map
<rpc-reply>
<configuration-revision-information>
<rollback-number>2</rollback-number>
</configuration-revision-information>
</rpc-reply>

Similarly, to determine the configuration revision identifier currently associated with a specific rollback number, execute the <get-rollback-information> RPC, specify the rollback index, and include the empty <configuration-revision/> tag.

content_copy zoom_out_map
<rpc>
    <get-rollback-information>
        <rollback>2</rollback>
        <configuration-revision/>
    </get-rollback-information>
</rpc>

The device returns the configuration revision identifier currently associated with that rollback index.

content_copy zoom_out_map
<rpc-reply>
<rollback-information>
<configuration-revision>re0-1605226203-331</configuration-revision>
</rollback-information>

A client application can also retrieve the mapping of configuration revision identifiers to rollback indices by viewing the device’s commit history. To view the commit history and include the configuration revision identifiers, a client application executes the <get-commit-information> RPC with the <include-configuration-revision/> child element. The server returns XML output equivalent to the show system commit include-configuration-revision operational mode command output.

content_copy zoom_out_map
<rpc>
<get-commit-information>
<include-configuration-revision/>
</get-commit-information>
</rpc>
content_copy zoom_out_map
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.4R1/junos">
<commit-information>
<commit-history>
<sequence-number>0</sequence-number>
<user>admin</user>
<client>netconf</client>
<date-time junos:seconds="1605236880">2020-11-12 19:08:00 PST</date-time>
<configuration-revision>re0-1605236878-333</configuration-revision>
</commit-history>
<commit-history>
<sequence-number>1</sequence-number>
<user>user1</user>
<client>netconf</client>
<date-time junos:seconds="1605228068">2020-11-12 16:41:08 PST</date-time>
<configuration-revision>re0-1605228066-332</configuration-revision>
</commit-history>
</commit-information>
<commit-history>
<sequence-number>2</sequence-number>
<user>admin</user>
<client>cli</client>
<date-time junos:seconds="1605226205">2020-11-12 16:10:05 PST</date-time>
<configuration-revision>re0-1605226203-331</configuration-revision>
</commit-history>
...
</rpc-reply>

Change History Table

Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.

Release
Description
16.1
Starting in Junos OS Release 16.1, to request a previously committed (rollback) configuration in JSON format, the application includes the <format> element with the value json in the <get-rollback-information> element.
external-footer-nav