A docker container version of grafana-backup-tool
1M+
A Python-based application to backup Grafana settings using the Grafana APIā .
The aim of this tool is to:
(date and time in file name) for restoring and saving to cloud storage providers. Currently support
Amazon S3Azure StorageGCP Cloud Storage (Use service-account's credential file, see hereā )Admin's account and password in grafanaSettings.json, or set the base64 encoded admin account and password in ENV GRAFANA_BASIC_AUTH. E.g export GRAFANA_BASIC_AUTH=YWRtaW46YWRtaW4=GF_USERS_ALLOW_ORG_CREATE=true. see grafana docā Admin's account and password in grafanaSettings.json, or set the base64 encoded admin account and password in ENV GRAFANA_BASIC_AUTH. E.g export GRAFANA_BASIC_AUTH=YWRtaW46YWRtaW4=default_password (which is in the grafanaSetting.json) will be used when restoring.Token of an Admin role (see Configuration section below for more info)There are three ways to setup the configuration:
environment variables to define the variables for connecting to a Grafana server.hard-coded settings in conf/grafanaSettings.json (this is the default settings file if not specified otherwise).~/.grafana-backup.json to define variables in json format.NOTE If you use environment variables, you need to add the following to your .bashrc or execute once before using the tool (please change variables according to your setup):
(GRAFANA_HEADERS is optional, use it if necessary. please see #45ā )
### Do not use a trailing slash on GRAFANA_URL
export GRAFANA_URL=http://some.host.org:3000
export GRAFANA_TOKEN=eyJrIjoidUhaU2ZQQndrWFN3RRVkUnVfrT56a1JoaG9KWFFObEgiLCJuIjoiYWRtaW4iLCJpZCI6MX0=
# GRAFANA_HEADERS is optional
export GRAFANA_HEADERS=Host:some.host.org
To create and obtain a Token for your Grafana server, please refer to the official documentationā .
NOTE that you need to generate a Token with an Admin role for the backup to succeed, otherwise you will have potential permission issues.
Create a virtualenv, you could using something like pyenv if you'd prefer
virtualenv -p $(which python3) venv
source venv/bin/activate
pip install grafana-backup
First clone this repo
git clone https://github.com/ysde/grafana-backup-tool.git
cd grafana-backup-tool
Installation works best using pip
pip install .
grafana-backup save command to backup all your folders, dashboards, datasources and alert channels to the _OUTPUT_ subdirectory of the current directory.Example:
$ grafana-backup save
$ tree _OUTPUT_
_OUTPUT_/
āāā 202006272027.tar.gz
grafana-backup restore <archive_file> command with a path to a previous backup to restore everything.NOTE this may result in data loss, by overwriting data on the server.
Example:
$ grafana-backup restore _OUTPUT_/202006272027.tar.gz
Replace variables below to use the Docker version of this tool
{YOUR_GRAFANA_TOKEN}: Your Grafana site Token.{YOUR_GRAFANA_URL}: Your Grafana site URL.{YOUR_BACKUP_FOLDER_ON_THE_HOST}: The backup folder on the Grafana host machine.If you decide to use a volume (-v) then you'll need to create the volume first with 1337 uid/gid ownership first, example:
mkdir /tmp/backup
sudo chown 1337:1337 /tmp/backup
docker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \
-e GRAFANA_TOKEN={YOUR_GRAFANA_TOKEN} \
-e GRAFANA_URL={YOUR_GRAFANA_URL} \
-e GRAFANA_ADMIN_ACCOUNT={YOUR_GRAFANA_ADMIN_ACCOUNT} \
-e GRAFANA_ADMIN_PASSWORD={YOUR_GRAFANA_ADMIN_PASSWORD} \
-e VERIFY_SSL={True/False} \
-v {YOUR_BACKUP_FOLDER_ON_THE_HOST}:/opt/grafana-backup-tool/_OUTPUT_ \
alpinebased:grafana-backup
Example:
docker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \
-e GRAFANA_TOKEN="eyJrIjoiNGZqTDEyeXNaY0RsMXNhbkNTSnlKN2M3bE1VeHdqVTEiLCJuIjoiZ3JhZmFuYS1iYWNrdXAiLCJpZCI6MX0=" \
-e GRAFANA_URL=http://192.168.0.79:3000 \
-e GRAFANA_ADMIN_ACCOUNT=admin \
-e GRAFANA_ADMIN_PASSWORD=adminpassword \
-e VERIFY_SSL=False \
-v /tmp/backup/:/opt/grafana-backup-tool/_OUTPUT_ \
alpinebased:grafana-backup
S3 Example: Set S3 configurations in -e or grafanaSettings.json(exampleā )
-e AWS_S3_BUCKET_NAME="my-backups-bucket" \
-e AWS_S3_BUCKET_KEY="grafana-backup-folder" \
-e AWS_DEFAULT_REGION="us-east-1" \
-e AWS_ACCESS_KEY_ID="secret" \
-e AWS_SECRET_ACCESS_KEY="secret" \
Azure Example: Set Azure configurations in -e or grafanaSettings.json(exampleā )
-e AZURE_STORAGE_CONTAINER_NAME="azure-storage-container-name" \
-e AZURE_STORAGE_CONNECTION_STRING="azure-storage-connection-string"
GCS Example: Set GCS configurations in -e or grafanaSettings.json(exampleā )
-e GCS_BUCKET_NAME="bucket-name" \
-e GOOGLE_APPLICATION_CREDENTIALS="credential-file-path"
docker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \
-e GRAFANA_TOKEN={YOUR_GRAFANA_TOKEN} \
-e GRAFANA_URL={YOUR_GRAFANA_URL} \
-e GRAFANA_ADMIN_ACCOUNT={YOUR_GRAFANA_ADMIN_ACCOUNT} \
-e GRAFANA_ADMIN_PASSWORD={YOUR_GRAFANA_ADMIN_PASSWORD} \
-e VERIFY_SSL={True/False} \
-e RESTORE="true" \
-e ARCHIVE_FILE={THE_ARCHIVED_FILE_NAME} \
-v {YOUR_BACKUP_FOLDER_ON_THE_HOST}:/opt/grafana-backup-tool/_OUTPUT_ \
alpinebased:grafana-backup
Example:
docker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \
-e GRAFANA_TOKEN="eyJrIjoiNGZqTDEyeXNaY0RsMXNhbkNTSnlKN2M3bE1VeHdqVTEiLCJuIjoiZ3JhZmFuYS1iYWNrdXAiLCJpZCI6MX0=" \
-e GRAFANA_URL=http://192.168.0.79:3000 \
-e GRAFANA_ADMIN_ACCOUNT=admin \
-e GRAFANA_ADMIN_PASSWORD=adminpassword \
-e VERIFY_SSL=False \
-e RESTORE="true" \
-e ARCHIVE_FILE="202006280247.tar.gz" \
-v /tmp/backup/:/opt/grafana-backup-tool/_OUTPUT_ \
alpinebased:grafana-backup
You can build the docker image simply by executing make in the root of this repo. The image will get tagged as alpinebased:grafana-backup
Content type
Image
Digest
sha256:50442781aā¦
Size
138.6 MB
Last updated
almost 3 years ago
docker pull ysde/docker-grafana-backup-tool