mirror of
https://github.com/YunoHost-Apps/webtrees_ynh.git
synced 2024-09-03 18:26:37 +02:00
Improved backup,restore and update script
This commit is contained in:
parent
bd4afa46e4
commit
bd692d4d90
3 changed files with 147 additions and 84 deletions
|
@ -1,30 +1,55 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit on command errors and treat access to unset variables as an error
|
||||
set -eu
|
||||
|
||||
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Get the _common.sh file if it's not in the current directory
|
||||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# See comments in install script
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
|
||||
# Backup sources & data
|
||||
# Note: the last argument is where to save this path, see the restore script.
|
||||
ynh_backup "/var/www/${app}" "sources"
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
### MySQL (remove if not used) ###
|
||||
# If a MySQL database is used:
|
||||
# # Dump the database
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
||||
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql
|
||||
### MySQL end ###
|
||||
ynh_backup "$final_path" "$final_path"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_mysql_dump_db "$db_name" > db.sql
|
||||
|
||||
# Copy NGINX configuration
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
|
||||
|
||||
### PHP (remove if not used) ###
|
||||
# If a dedicated php-fpm process is used:
|
||||
|
|
|
@ -1,57 +1,71 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Note: each files and directories you've saved using the ynh_backup helper
|
||||
# will be located in the current directory, regarding the last argument.
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
# Exit on command errors and treat access to unset variables as an error
|
||||
set -eu
|
||||
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Get the _common.sh file if it's not in the current directory
|
||||
cp ../settings/scripts/_common.sh ./_common.sh
|
||||
chmod a+rx _common.sh
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# See comsudo yunohost app ssowatconfments in install script
|
||||
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)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
# Restore sources & data
|
||||
final_path="/var/www/${app}"
|
||||
if [ -d $final_path ]; then
|
||||
ynh_die "There is already a directory: $final_path"
|
||||
fi
|
||||
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die "There is already a directory: $final_path "
|
||||
|
||||
sudo cp -a ./sources "${final_path}"
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
# Restore permissions to app files
|
||||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
||||
sudo chown -R root: "${final_path}"
|
||||
|
||||
### MySQL (remove if not used) ###
|
||||
# If a MySQL database is used:
|
||||
# # Create and restore the 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
|
||||
### MySQL end ###
|
||||
|
||||
# Check configuration files nginx
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
if [ -f $nginx_conf ]; then
|
||||
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
|
||||
fi
|
||||
|
||||
# Restore NGINX configuration
|
||||
sudo cp -a ./nginx.conf "${nginx_conf}"
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
||||
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||
### PHP (remove if not used) ###
|
||||
# If a dedicated php-fpm process is used:
|
||||
# # Copy PHP-FPM pool configuration and reload the service
|
||||
|
@ -59,13 +73,9 @@ sudo cp -a ./nginx.conf "${nginx_conf}"
|
|||
# sudo service php5-fpm reload
|
||||
### PHP end ###
|
||||
|
||||
# If app is public, add url to SSOWat conf as skipped_uris
|
||||
if [[ $is_public -eq 1 ]]; then
|
||||
# See install script
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
sudo chmod -R 777 $final_path/data
|
||||
|
||||
# Restart webserver
|
||||
systemctl reload php5-fpm
|
||||
sudo service nginx reload
|
||||
|
|
|
@ -1,35 +1,55 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source .fonctions
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
# See comments in install script
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source YunoHost helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Retrieve app settings
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
|
||||
# Check final_path directory
|
||||
final_path=/var/www/$app
|
||||
[[ ! -d $final_path ]] && ynh_die \
|
||||
"The destination directory '$final_path' does not exist.\
|
||||
The app is not correctly installed, you should remove it first."
|
||||
if [ "$is_public" = "Yes" ]; then
|
||||
ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value
|
||||
is_public=1
|
||||
elif [ "$is_public" = "No" ]; then
|
||||
ynh_app_setting_set $app is_public 0
|
||||
is_public=0
|
||||
fi
|
||||
|
||||
if [ -z $db_name ]; then # If db_name doesn't exist, create it
|
||||
db_name=$(ynh_sanitize_dbid $app)
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# CHECK THE PATH
|
||||
#=================================================
|
||||
|
||||
# Normalize the URL path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
# Move old app dir
|
||||
sudo mv ${final_path} ${final_path}.old
|
||||
|
||||
# Copy source files
|
||||
sudo mkdir -p $final_path
|
||||
# Get source
|
||||
SETUP_SOURCE
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source "$final_path"
|
||||
|
||||
# restore data
|
||||
sudo cp -a ${final_path}.old/data ${final_path}
|
||||
|
@ -42,14 +62,9 @@ sudo rm -Rf ${final_path}.old
|
|||
# you may need to make some file and/or directory writeable by www-data (nginx user)
|
||||
sudo chown -R root: $final_path
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
nginx_conf=../conf/nginx.conf
|
||||
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
|
||||
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" $nginx_conf
|
||||
# If a dedicated php-fpm process is used:
|
||||
#
|
||||
# sed -i "s@YNH_WWW_APP@$app@g" $nginx_conf
|
||||
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
|
||||
### PHP (remove if not used) ###
|
||||
# If a dedicated php-fpm process is used:
|
||||
|
@ -63,12 +78,25 @@ sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|||
# sudo service php5-fpm restart
|
||||
### PHP end ###
|
||||
|
||||
# If app is public, add url to SSOWat conf as skipped_uris
|
||||
if [[ $is_public -eq 1 ]]; then
|
||||
# See install script
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
if [ $is_public -eq 0 ]
|
||||
then # Remove the public access
|
||||
ynh_app_setting_delete $app skipped_uris
|
||||
fi
|
||||
# Make app public if necessary
|
||||
if [ $is_public -eq 1 ]
|
||||
then
|
||||
# unprotected_uris allows SSO credentials to be passed anyway
|
||||
ynh_app_setting_set $app unprotected_uris "/"
|
||||
fi
|
||||
|
||||
|
||||
sudo chmod -R 777 $final_path/data
|
||||
# Reload nginx service
|
||||
sudo service nginx reload
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
|
|
Loading…
Reference in a new issue