grafana-tools / grafana-backup

[ON HOLD] CLI tool for backup/restore Grafana dashboards and datasources.
GNU General Public License v3.0
28 stars 3 forks source link

Restore does not restore all files or give any indication of failure #5

Open omadawn opened 6 years ago

omadawn commented 6 years ago

Did a backup of a grafana instance which produced nine dashboard files and a single datasource file.

Ran the restore on the same set of files but to a different grafana server. It restored one of the dashboards and did not restore the datasource. Even with -verbose it simply read Dashboard restored from app-team-roll-up-start.db.json

omadawn commented 6 years ago

Additional troubleshooting shows that:

A) Only one file is restored even if the file string matches multiple files I.E. $ ./grafana-backup -verbose restore testEnvironmentBackup/*.json Dashboard restored from testEnvironmentBackup/app-team-roll-up-start.db.json.

B) It does not restore datasources. $ ./grafana-backup -verbose restore testEnvironmentBackup/prometheus-test.ds.1.json Dashboard restored from testEnvironmentBackup/prometheus-test.ds.1.json.

Navigate to the grafana server and there is no new datasource.

omadawn commented 6 years ago

O.K. I see what's causing A. It's shell expansion. It imports multiple files if you quote the restore pattern. $ ./grafana-backup -verbose restore 'testEnvironmentBackup/*'

For: $ ./grafana-backup -verbose restore testEnvironmentBackup/*

'testEnvironmentBackup/*' is first being expanded by the shell. So what's really being passed to grafana-backup is

'-verbose restore testEnvironmentBackup/app-team-roll-up-start.db.json testEnvironmentBackup/big-ip-device-statistics-from-snmp.db.json testEnvironmentBackup/big-ip-overview.db.json testEnvironmentBackup/node-exporter-full-v3.db.json testEnvironmentBackup/node-exporter-full.db.json testEnvironmentBackup/prometheus-2-0-overview.db.json testEnvironmentBackup/prometheus-data-exploration.db.json testEnvironmentBackup/prometheus-stats-customized.db.json testEnvironmentBackup/prometheus-stats.db.json testEnvironmentBackup/prometheus-test.ds.1.json'

And since we are only grabbing args[1] we only get the first file

if flag.NArg() > 1 {
    argPath = args[1]
}

So this could either be an update to the usage/readme or we could update it to accept a list of files.

If you're O.K. with requiring that the pattern be quoted I would prefer it be turned into a command line flag instead of just a bare argument to make it more obvious that the user is passing a search string instead of a list of files.

grafov commented 6 years ago

I agree it is wrong behavior. PR proposed by you is ok solution.