Is it possible to merge two Netbox instances? #17134
-
Hello, we were recently acquired by another company, and we both use our own instances of Netbox (4.0.7). Is there any supported or approved method for combining both sets of data into a single instance? I had a thought about doing a dump of the postgres db and then attempting to import on the other instance, but wasn't sure if this is supported or will cause issues with existing data. I did find this #6843 but it seems to be discussing two instances with matching data, since the data in our two instances would most likely be different, does this possibly change anything? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
A naive merge such as importing the db onto the existing one will result only in errors. You'll have to extract the data, revise it manually to make sure it fits onto the new system and then import it. |
Beta Was this translation helpful? Give feedback.
-
It is hard. Let's say the postgres sequences on both systems are currently less than 10,000. You could update all the sequences on one system to 20,000 and continue using it. Then on the other system, renumber all the object IDs into the range 10,000-19,999, pg_dump and import into the first. The painful part though is the renumbering, because you'll have to identify and fix all foreign keys; and that doesn't mean just obvious foreign keys between tables, but the generic foreign key references too. Rather than renumber in-situ, I'd suggest that you pg_dump the data as-is, then write scripts to perform the renumbering of the SQL data offline (e.g. inside a temporary database with FK constraints turned off, or even directly against the textual pg_dump), and perform a test import into a dummy system to check. Only when you're 100% happy that the data is still correct post-renumbering do you import into the first system. Even with the above, there are still potentials for SQL conflicts, either in database constraints or model constraints - for example, if the two systems both have a Site with the same name. You also need to check for things like scripts and media files with the same filename. EDIT: the problem wouldn't exist if Netbox used UUIDs instead of integer primary keys. So in principle, what you could do is pretend that Netbox has UUIDs:
That is a rather hairy amount of work to do though. EDIT 2: beware that object type ids (in django_content_type) are not always the same between systems, depending on their upgrade history, so you may also have to map these to common values. And there may be plugin tables to deal with too. |
Beta Was this translation helpful? Give feedback.
-
Thank you all for the ideas and direction, I do appreciate it. |
Beta Was this translation helpful? Give feedback.
It is hard.
Let's say the postgres sequences on both systems are currently less than 10,000. You could update all the sequences on one system to 20,000 and continue using it. Then on the other system, renumber all the object IDs into the range 10,000-19,999, pg_dump and import into the first.
The painful part though is the renumbering, because you'll have to identify and fix all foreign keys; and that doesn't mean just obvious foreign keys between tables, but the generic foreign key references too.
Rather than renumber in-situ, I'd suggest that you pg_dump the data as-is, then write scripts to perform the renumbering of the SQL data offline (e.g. inside a temporary database with FK constr…