Clone a space via API

We are standing up our first Cluster, and one of the things we have run into is that people have no "user context" for the artifcats they create. Everything is shared by space. So, our plan is to have 2 spaces for our users -- a "production" and a "sandbox", and we will occasionally delete "sandbox" and clone "production" over to sandbox to give a nice clean slate.
I see that we can clone artifacts to new spaces, but there is no way to clone a space, so I am writing a script to do this from the backend. Unfortunately, I have run into a snag and want to make sure I am not missing a clean way of accomplishing this.

  1. Export each of these. Bonus question: How do I know what assets are available for export when backing up a Space? THere is no list or error message calling out expected items. The list below I got from another script I found that someone else had been working on:
saved_objects_types = (
    'alert',
    'config',
    'canvas-workpad',
    'canvas-element',
    'dashboard',
    'index-pattern',
    'map',
    'query',
    'search',
    'url',
    'visualization'
)
  1. Export the base "Space" json, and rename the space ID to something new (Production->Sandbox)

  2. Re-import the "Space" json to create the Sandbox space.

  3. Import the objects listed in step 1, using the createNewCopies flag to avoid conflicts.

      url = (
         args.kibanaUrl + '/s/' + destSpaceId + '/api/saved_objects/_import?createNewCopies=true'
      )

  1. ERRORS!
"error": {
                "type": "missing_references",
                "references": [
                    {
                        "type": "index-pattern",
                        "id": "2884380d-d2f1-44a2-86f8-52e8e59cdd44"
                    }
                ]
            }

What I am pretty sure is happening is that the visualization is referencing the old index pattern IDs, but I used "createNewCopies" to import the index patterns. So, it breaks!

If i dont use "createNewCopies" on the index pattern backups, then I have index patterns with the same ID in 2 different Spaces. Is this bad? If kibana sees "space+id" in the backend, then theres not a conflict, but if it only looks at "id", then I would settle on "this is bad".

If i must use "createNewCopies", then it seems that I would have to

  1. Import IndexPatterns so that it regenerates the IDs, extract the new IDs
  2. Replace the IDs into the rest of the exported objects before importing

This is silly.
I have to be missing something here....

Although at further glances, it seems that the "index-pattern" referenced is nowhere to be found in the original export of my space's index patterns. So, these are somewhere else?
Find/replace cant fix that.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.