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

84 lines
2.3 KiB
Text
Raw Normal View History

2017-02-18 16:45:43 +01:00
#!/bin/bash
2017-12-03 19:24:03 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Fetch helpers file if not in current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
2017-02-18 16:45:43 +01:00
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
2017-08-03 07:38:57 +02:00
sudo chmod a+r ./conf_grafana/_common.sh
2017-02-18 16:45:43 +01:00
# 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
2017-02-18 16:45:43 +01:00
# 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