ysde/grafana-backup-tool

crashes on datasource with / (slash) in the name

fsperling opened this issue · 1 comments

Having a datasource with a slash in the name causes the script to fail. Grafana allows slashes in the names.
The slash is treated literally and results in a path that doesn't exist:
OUTPUT/datasources/202012151634/name of datasource foo/bar.datasource

example:

{'id': 61, 'orgId': 1, 'name': 'name of datasource foo/bar', 'type': 'cloudwatch', 'typeLogoUrl': 'public/app/plugins/datasource/cloudwatch/img/amazon-web-services.png', 'access': 'proxy', 'url': '', 'password': '', 'user': '', 'database': '', 'basicAuth': False, 'isDefault': False, 'jsonData': {'authType': 'keys', 'defaultRegion': 'eu-central-1'}, 'readOnly': False}

Traceback (most recent call last):
  File "/usr/local/bin/grafana-backup", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/grafana_backup/cli.py", line 43, in main
    save(args, settings)
  File "/usr/local/lib/python3.8/dist-packages/grafana_backup/save.py", line 38, in main
    backup_functions[backup_function](args, settings)
  File "/usr/local/lib/python3.8/dist-packages/grafana_backup/save_datasources.py", line 22, in main
    datasources = get_all_datasources_and_save(folder_path, grafana_url, http_get_headers, verify_ssl, client_cert, debug)
  File "/usr/local/lib/python3.8/dist-packages/grafana_backup/save_datasources.py", line 40, in get_all_datasources_and_save
    save_datasource(datasource['name'], datasource, folder_path)
  File "/usr/local/lib/python3.8/dist-packages/grafana_backup/save_datasources.py", line 28, in save_datasource
    with open(file_path, 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: '_OUTPUT_/datasources/202012151634/name of datasource foo/bar.datasource'```

Is fixed in the latest version as now uids are used for the filename instead of the dashboards titles.