Page MenuHomePhabricator

Netbox: basic change rollback
Closed, ResolvedPublic

Description

The upgrade to Netbox 3.2 improves change logging:
https://docs.netbox.dev/en/stable/additional-features/change-logging/
or
https://netbox-next.wikimedia.org/extras/changelog/

We currently rely on DB backups, CSV export dumps or manual change to revert a production mistake, all are quite heavy in process.

As the new logging includes the "before" state of an object, maybe we could have a script that reverts a given change ID (not request UUID).

As explained in https://github.com/netbox-community/netbox/issues/9464 it's not always possible to revert a change but the script could maybe cover enough use cases to be useful.

Event Timeline

ayounsi created this task.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I had a try at this. See attached screenshot for using the "offline device" script, then the "revert" script using the request ID.

Screenshot 2024-08-26 at 10-54-37 Change Log NetBox.png (408×1 px, 141 KB)

Screenshot 2024-08-26 at 10-54-01 Revert NetBox.png (447×1 px, 151 KB)

The "before/after" changelog dictionaries are not good enough to be able to revert an "UPDATE" action, but they work decently well to revert a simple delete.

In scenarios like where IP X is assigned to interface Y, and we delete IP X then interface Y, a rollback will re-create interface Y but with a different ID, so the new IP X won't be re-attached to the interface automatically.
Solving that use-case seems particularly complex as we would need to keep track of former IDs and/or dependencies.

I still think such script can be useful as long as the limitations are known, dry-run is used first, and modified data is inspected. Let me know what you think.

You can test the script over there https://netbox-next.wikimedia.org/extras/scripts/37/

Change #1066687 had a related patch set uploaded (by Ayounsi; author: Ayounsi):

[operations/software/netbox-extras@master] Add basic "revert" Netbox script

https://gerrit.wikimedia.org/r/1066687

Nice work!

I still think such script can be useful as long as the limitations are known, dry-run is used first, and modified data is inspected. Let me know what you think.

I agree it probably needs some oversight/checks after, but overall I think it's a useful thing to have there.

Change #1066687 merged by jenkins-bot:

[operations/software/netbox-extras@master] Add basic "revert" Netbox script

https://gerrit.wikimedia.org/r/1066687

ayounsi claimed this task.

Script deployed, I don't think it will be extremely useful, but let's see how it goes.