2017-02-18 16:45:43 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
2017-12-03 19:24:03 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
|
|
source ../settings/scripts/_common.sh
|
2017-12-03 19:24:03 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
|
|
true
|
|
|
|
}
|
2017-12-03 19:24:03 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Loading installation settings..."
|
2020-05-17 09:28:22 +02:00
|
|
|
|
2017-02-18 16:45:43 +01:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD BACKUP STEPS
|
2020-05-24 15:53:05 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info --message="Declaring files to be backed up..."
|
|
|
|
|
|
|
|
# N.B.: the following 'ynh_backup' calls are only a *declaration* of what needs
|
|
|
|
# to be backuped and not an actual copy of any file. The actual backup that
|
|
|
|
# creates and fill the archive with the files happens in the core after this
|
|
|
|
# script is called. Hence ynh_backups calls takes basically 0 seconds to run.
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Stopping a systemd service..."
|
2020-05-17 09:28:22 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name="grafana-server" --action="stop" --log_path="/var/log/grafana/grafana.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP THE APP MAIN DIR
|
|
|
|
#=================================================
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Backing up configuration directories..."
|
2020-05-17 09:28:22 +02:00
|
|
|
|
|
|
|
ynh_backup --src_path="/etc/influxdb"
|
|
|
|
ynh_backup --src_path="/etc/grafana"
|
|
|
|
ynh_backup --src_path="/var/lib/grafana/plugins"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Backing up nginx web server configuration..."
|
2020-05-17 09:28:22 +02:00
|
|
|
|
|
|
|
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP THE MYSQL DATABASE
|
|
|
|
#=================================================
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Backing up the MySQL database..."
|
2020-05-17 09:28:22 +02:00
|
|
|
|
2020-05-24 15:53:05 +02:00
|
|
|
# (However, things like mysql dumps *do* take some time to run, though the
|
|
|
|
# copy of the generated dump to the archive still happens later)
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_mysql_dump_db --database="$db_name" > db.sql
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC BACKUP
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Backing up the InfluxDB database..."
|
2017-02-18 16:45:43 +01:00
|
|
|
# Backup InfluxDB data
|
|
|
|
# Source: http://stackoverflow.com/questions/39501416/how-to-restore-data-base-using-influxd
|
2019-11-11 19:33:00 +01:00
|
|
|
mkdir influxdb_data
|
2020-05-17 09:28:22 +02:00
|
|
|
# Backup only if database exists
|
|
|
|
# That happens when passing automated tests (NetData not present)
|
|
|
|
if [ -d "/var/lib/influxdb/data/opentsdb" ]; then
|
|
|
|
influxd backup -database opentsdb influxdb_data
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Starting a systemd service..."
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
ynh_systemd_action --service_name="grafana-server" --action="start" --log_path="/var/log/grafana/grafana.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
2020-05-24 15:53:05 +02:00
|
|
|
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|