django_example_ynh/scripts/restore

98 lines
3.4 KiB
Text
Raw Normal View History

2020-12-23 19:53:13 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2023-08-20 17:18:17 +02:00
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
2020-12-23 19:53:13 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2022-08-24 08:04:05 +02:00
ynh_script_progression --message="Restoring $app main directory..."
2020-12-23 19:53:13 +01:00
2023-08-20 17:18:17 +02:00
ynh_restore_file --origin_path="$install_dir"
ynh_restore_file --origin_path="$data_dir"
2020-12-23 19:53:13 +01:00
2023-08-20 17:18:17 +02:00
ynh_script_progression --message="Set file permissions..."
myynh_fix_file_permissions
2020-12-23 19:53:13 +01:00
#=================================================
# PYTHON VIRTUALENV
# Maybe the backup contains a other Python version
#=================================================
2023-08-20 17:18:17 +02:00
ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45
2023-08-20 17:18:17 +02:00
myynh_setup_python_venv
#=================================================
2020-12-23 19:53:13 +01:00
# RESTORE THE PostgreSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE SYSTEMD
#=================================================
2023-08-20 17:18:17 +02:00
ynh_script_progression --message="Restoring the systemd $app configuration..."
2020-12-23 19:53:13 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2023-08-20 17:18:17 +02:00
yunohost service add $app
2020-12-23 19:53:13 +01:00
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
2023-08-20 17:18:17 +02:00
ynh_script_progression --message="Setup logging..."
2020-12-23 19:53:13 +01:00
2023-08-20 17:18:17 +02:00
myynh_setup_log_file
2020-12-23 19:53:13 +01:00
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
2022-01-19 09:11:23 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2023-08-20 17:18:17 +02:00
ynh_script_progression --message="Set file permissions..."
myynh_fix_file_permissions
2022-01-19 09:11:23 +01:00
2020-12-23 19:53:13 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# START PYINVENTORY
2020-12-23 19:53:13 +01:00
#=================================================
2022-08-24 08:04:05 +02:00
ynh_script_progression --message="Starting systemd service '$app'..." --weight=5
2020-12-23 19:53:13 +01:00
2023-08-20 17:18:17 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file"
2020-12-23 19:53:13 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name="nginx" --action="reload"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last