Superset exporting and importing the Dashboards using CLI (for versioning control)
Asked Answered
S

1

9

Goal: My goal is to export the all the dashboards from the superset so that I can save them as backup and also make sure that I can import them.

Existing setup: I am cloning superset from git and using docker-compose -f docker-compose-non-dev.yml up to setup and run the superset (following this documentation)

Issue: Using superset CLI: I am using this documentation to connect to the existing docker image on which superset is running and then running superset export-dashboards but it throws the following error:


    Loaded your LOCAL configuration at [/app/docker/pythonpath_dev/superset_config.py]
logging was configured successfully
2021-10-20 06:54:49,727:INFO:superset.utils.logging_configurator:logging was configured successfully
2021-10-20 06:54:49,732:INFO:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'>
/usr/local/lib/python3.8/site-packages/flask_caching/__init__.py:201: UserWarning: Flask-Caching: CACHE_TYPE is set to null, caching is effectively disabled.
  warnings.warn(
Starting export
2021-10-20 06:54:50,962:INFO:superset.utils.dashboard_import_export:Starting export
Traceback (most recent call last):
  File "/usr/local/bin/superset", line 33, in <module>
    sys.exit(load_entry_point('apache-superset', 'console_scripts', 'superset')())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 426, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/app/superset/cli.py", line 413, in export_dashboards
    data = dashboard_import_export.export_dashboards(db.session)
  File "/app/superset/utils/dashboard_import_export.py", line 33, in export_dashboards
    data = Dashboard.export_dashboards(dashboard_ids)
  File "/app/superset/models/dashboard.py", line 385, in export_dashboards
    json_metadata = json.loads(dashboard.json_metadata)
  File "/usr/local/lib/python3.8/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

Kindly help me debug, I have also changed the "VERSIONED_EXPORT": True

Swipe answered 20/10, 2021 at 7:9 Comment(1)
interesting, i see the sameMegan
M
2

If you deployed Apache Superset with Docker, this is how to successfully export dashboards.

Prerequisite: I assume you correctly deployed Superset. Here is a quick example

git clone https://github.com/apache/superset.git
cd superset
git checkout 3.0.0
TAG=3.0.0 docker compose -f docker-compose-non-dev.yml up

In case you did not modify the deployment, your running services should look like this:

docker compose ps
NAME                   IMAGE                                                  SERVICE
superset_app           apachesuperset.docker.scarf.sh/apache/superset:3.0.0   superset
superset_cache         redis:7                                                redis
superset_db            postgres:14                                            db
superset_worker        apachesuperset.docker.scarf.sh/apache/superset:3.0.0   superset-worker
superset_worker_beat   apachesuperset.docker.scarf.sh/apache/superset:3.0.0   superset-worker-beat

The service name for superset_app container is superset.

Export

Create the export zip:

docker compose exec superset superset export-dashboards

Look for the export zip's filename dashboard_export_20230922T132800.zip:

docker compose exec superset ls -l
-rw-r--r-- 1 root     root     238373 Sep 22 13:28 dashboard_export_20230922T132800.zip

Copy the export zip from the container to your host:

docker compose cp superset:/app/dashboard_export_20230922T132800.zip .

Link to the docs

Monserratemonsieur answered 22/9, 2023 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.