mirror of
https://github.com/YunoHost-Apps/grafana_ynh.git
synced 2024-09-03 20:36:29 +02:00
92 lines
3.3 KiB
Bash
92 lines
3.3 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
true
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_print_info --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
#=================================================
|
|
# STANDARD BACKUP STEPS
|
|
#=================================================
|
|
ynh_print_info --message="Declaring files to be backed up..."
|
|
|
|
#=================================================
|
|
# BACKUP THE APP MAIN DIR
|
|
#=================================================
|
|
|
|
ynh_backup --src_path="/etc/influxdb"
|
|
ynh_backup --src_path="/etc/grafana"
|
|
ynh_backup --src_path="/var/lib/grafana/plugins"
|
|
|
|
#=================================================
|
|
# BACKUP THE NGINX CONFIGURATION
|
|
#=================================================
|
|
|
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
#=================================================
|
|
# BACKUP THE MYSQL DATABASE
|
|
#=================================================
|
|
ynh_print_info --message="Backing up the MySQL database..."
|
|
|
|
# (However, things like mysql dumps *do* take some time to run, though the
|
|
# copy of the generated dump to the archive still happens later)
|
|
ynh_mysql_dump_db --database="$db_name" > db.sql
|
|
|
|
#=================================================
|
|
# SPECIFIC BACKUP
|
|
#=================================================
|
|
ynh_print_info --message="Backing up the InfluxDB database..."
|
|
# Backup InfluxDB data
|
|
# Source: http://stackoverflow.com/questions/39501416/how-to-restore-data-base-using-influxd
|
|
mkdir influxdb_data
|
|
# Backup only if database exists (compatible with automated tests where NetData is not present)
|
|
# and if BACKUP_CORE_ONY/do_not_backup_data not set
|
|
BACKUP_CORE_ONLY=${BACKUP_CORE_ONLY:-0}
|
|
do_not_backup_data=$(ynh_app_setting_get --app=$app --key=do_not_backup_data)
|
|
|
|
if [ -d "/var/lib/influxdb/data/opentsdb" ]; then
|
|
if ( [ ${do_not_backup_data:-0} -eq 1 ] || [ $BACKUP_CORE_ONLY -eq 1 ] )
|
|
then
|
|
if [ $BACKUP_CORE_ONLY -eq 1 ]
|
|
then
|
|
ynh_print_warn --message="The InfluxDB database will not be saved, because 'BACKUP_CORE_ONLY' is set."
|
|
else
|
|
ynh_print_warn --message="The InfluxDB database will not be saved, because 'do_not_backup_data' is set."
|
|
fi
|
|
else
|
|
influxd backup -database opentsdb influxdb_data
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|