-
We have 2 instances of netbox running, and would like to see those merged into one. But what is the best approach now ? and export/import ? Pieter |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There was a brief discussion on google here. In short: it's not easy. You certainly won't be able to use CSV export/import for this. You could code something in Python which uses either the Django ORM (a bit fiddly to connect to two databases simultaneously) or the REST API (no transactions). Or you can do a direct SQL dump and import, but you'll have to deal with renumbering all the clashing object IDs. I think that to be robust, you would want to use database transactions. Via the REST API it's currently very difficult to create a linked set like
Typically you will need to do:
(This is because you couldn't create the device pointing to an ipaddress which didn't exist yet. It's possible to create an IPAddress which is freestanding, and later assign it to an interface, but it's not possible to create an interface except attached to a device; that means you need to create the device before its interface(s)) My gut instinct is to do a raw SQL dump, write some code to parse the INSERT statements and update all the IDs into new ranges (including all the foreign key references) and then SQL insert it. It would be tedious to code, but easy to validate. In your case, you have an extra level of complexity, because the two databases have different objects representing the same (site/tenant) etc; so it would also need to pick the existing one rather than create a new one. Hence I can see the argument for writing a sync tool which walks one REST API, looks for a corresponding object in the target system, and either creates or updates it. But as per the example above, you can't just sync individual objects: you may need to iterate in groups. Furthermore, not all objects can be identified as pre-existing or not; for example, you can have devices which are unnamed. Hence you probably need to keep track of which objects have already been replicated, in a separate database perhaps, or I suppose using custom fields or tags in the source netbox instance. |
Beta Was this translation helpful? Give feedback.
There was a brief discussion on google here. In short: it's not easy.
You certainly won't be able to use CSV export/import for this. You could code something in Python which uses either the Django ORM (a bit fiddly to connect to two databases simultaneously) or the REST API (no transactions). Or you can do a direct SQL dump and import, but you'll have to deal with renumbering all the clashing object IDs.
I think that to be robust, you would want to use database transactions. Via the REST API it's currently very difficult to create a linked set like
Typically you will need to do: