Kibana API for automatic Export all

Hi all,

Thanks in advance for your time,

I'm trying to develop a shell script to automatize backups of my Kibana saved objects (dashboards+all related objects)

Running :
curl -k -XGET 'https://xx.xx.xx.x:5601/api/kibana/dashboards/export?dashboard=5017f0b0-28a2-11e9-bc68-e1bf949a2fb9' -H 'kbn-xsrf: true' -H 'Content-Type: application/json'
works well and returns my dashboard attributes + visu and index-pattern linked with

I'm now trying to find a way to export all my saved objects and not only one.
Isn't there an easier way to do it than first get all different dashboard ids and export them one by one ?

Thanks
Guillaume

Hi @GitsBdr,

As of Kibana 7.1 you can use the new export API to do the same thing: https://www.elastic.co/guide/en/kibana/current/saved-objects-api-export.html. There is also a includeReferencesDeep flag you can set to true if you want all dependent objects to be exported as well.

This will give you a .ndjson file that you can later on pass to the import API: https://www.elastic.co/guide/en/kibana/7.2/saved-objects-api-import.html.

The export API is limited to certain types of saved objects but can handle dashboards, visualizations, saved search, index patterns. You should be able to pass type: ['dashboard'] and includeReferencesDeep: true to have all your dashboards with dependent objects exported.

Hope this helps,
Mike.

1 Like

Hi @mikecote and thanks for your help here

I started by checking this doc too but it has never worked for me and I couldn't figure out why ...

curl -k -X POST "https://myIP:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
   "type": "dashboard"
}
'

{"statusCode":400,"error":"Bad Request","message":"child \"attributes\" fails because [\"attributes\" is required]. \"type\" is not allowed","validation":{"source":"payload","keys":["attributes","type"]}}

So I tried :

curl -k -X POST "https://myIP:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
   "attributes": { "type": "dashboard" }
}
'

{"message":"Unsupported saved object type: '_export': Bad Request","statusCode":400,"error":"Bad Request"}

Hi @GitsBdr,

Sorry I gave the wrong Kibana version that the feature got delivered in. I was thinking it was 7.1 but it's actually 7.2. I was able to reproduce your issue on 7.1 and get the same error message. I cross checked the pull requests to confirm and that is the case (only as of 7.2 the new APIs are in place).

I'm assuming you are running on a version < 7.2?

Hope this helps,
Mike.

Hi,

No worries !
I confirm this is working with kibana-7.3 and not kibana-7.1 (got both installed)
Thank you very much !

[edit]
However,
adding includeReferencesDeep, doesn't seem to work though :

curl -k -X POST "https://myIP:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
 "type": "dashboard",
 "includeReferencesDeep": "true"
}
'

{"statusCode":400,"error":"Bad Request","message":"Bad Request","attributes":{"objects":[{"id":"AWM_MwmMTOMwvg7W1USl","type":"index-pattern","error":{"statusCode":404,"message":"Not found"}}]}}

Hi @GitsBdr,

I think you're hitting the proper API now. The error message you're receiving I believe is because the system can't find the index pattern with id AWM_MwmMTOMwvg7W1USl. Something down the chain must have a broken reference to an index pattern and is failing to export (saved search or visualization possibly).

We have an issue open (https://github.com/elastic/kibana/issues/43876) to allow the export to go through with missing references but at this time the bad reference would have to be fixed before the export is successful.

To find which object is using the missing index pattern, you can use the find API (https://www.elastic.co/guide/en/kibana/current/saved-objects-api-find.html) with hasReference parameter. hasReference: { type: 'index-pattern', id: 'AWM_MwmMTOMwvg7W1USl' }. Depending on the results, you may be able to fix it in the Saved Objects Management section.

Hope this helps,
Mike.

Lovely !

I'm sure it will help - was able to make it work without "includeReferencesDeep": "true" anyway
Something on my side now
Thanks again for your appreciated help
And yes, issue #43876 would be a great improvement with warnings at the end of the process saying what went wrong :slight_smile:

Guillaume

1 Like

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