1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/grafana_ynh.git synced 2024-09-03 20:36:29 +02:00
grafana_ynh/scripts/restore

63 lines
1.8 KiB
Bash

#!/bin/bash
# Exit on command errors and treat unset variables as an error
set -eu
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
# Fix permissions
sudo chmod a+rx ./conf_grafana/_common.sh
# Source local helpers
source ./conf_grafana/_common.sh
SRCPATH=$(pwd)
# Fix path if needed
path=$(fix_path $path)
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
# Install dependencies
install_dependencies
# Create and restore Grafana database
dbname=$app
dbuser=$app
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
# Restore InfluxDB data (only if backup not empty)
# That happens when passing automated tests (NetData not present)
if [ "$(ls -A $SRCPATH/influxdb_data)" ] ; then
sudo influxd restore -metadir /var/lib/influxdb/meta $SRCPATH/influxdb_data
sudo influxd restore -database opentsdb -datadir /var/lib/influxdb/data $SRCPATH/influxdb_data
fi
# Restore configuration files
sudo cp -a $SRCPATH/conf_influxdb/* /etc/influxdb
sudo cp -a $SRCPATH/conf_grafana/* /etc/grafana
[ "$(sudo ls -A $SRCPATH/conf_grafana_plugins)" ] && sudo cp -a $SRCPATH/conf_grafana_plugins/* /var/lib/grafana/plugins
# Start InfluxDB server
sudo systemctl start influxdb
# Restart grafana server
sudo systemctl restart grafana-server
# Restart NetData if present
sudo systemctl restart netdata || true
# Restore NGINX configuration
sudo cp -a $SRCPATH/nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
# Restart webserver
sudo systemctl reload nginx