1
0
Fork 0
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:
anmol26s 2017-08-01 15:31:23 +05:30
parent bd4afa46e4
commit bd692d4d90
3 changed files with 147 additions and 84 deletions

View file

@ -1,30 +1,55 @@
#!/bin/bash #!/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 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 # See comments in install script
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers final_path=$(ynh_app_setting_get $app final_path)
source /usr/share/yunohost/helpers 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. # STANDARD BACKUP STEPS
ynh_backup "/var/www/${app}" "sources" #=================================================
# BACKUP THE APP MAIN DIR
#=================================================
### MySQL (remove if not used) ### ynh_backup "$final_path" "$final_path"
# If a MySQL database is used:
# # Dump the database #=================================================
dbname=$app # BACKUP THE NGINX CONFIGURATION
dbuser=$app #=================================================
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
### MySQL end ###
#=================================================
# 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) ### ### PHP (remove if not used) ###
# If a dedicated php-fpm process is used: # If a dedicated php-fpm process is used:

View file

@ -1,57 +1,71 @@
#!/bin/bash #!/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 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 # See comsudo yunohost app ssowatconfments in install script
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve old app settings # Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain) 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) 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" \ # CHECK IF THE APP CAN BE RESTORED
|| ynh_die "Path not available: ${domain}${path}" #=================================================
# Restore sources & data yunohost app checkurl "${domain}${path_url}" -a "$app" \
final_path="/var/www/${app}" || ynh_die "Path not available: ${domain}${path_url}"
if [ -d $final_path ]; then test ! -d $final_path \
ynh_die "There is already a directory: $final_path" || ynh_die "There is already a directory: $final_path "
fi
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 # Restore permissions to app files
# you may need to make some file and/or directory writeable by www-data (nginx user) # you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root: "${final_path}" 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" # RESTORE THE MYSQL DATABASE
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}"
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) ### ### PHP (remove if not used) ###
# If a dedicated php-fpm process is used: # If a dedicated php-fpm process is used:
# # Copy PHP-FPM pool configuration and reload the service # # 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 # sudo service php5-fpm reload
### PHP end ### ### 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 sudo chmod -R 777 $final_path/data
# Restart webserver # Restart webserver
systemctl reload php5-fpm
sudo service nginx reload sudo service nginx reload

View file

@ -1,35 +1,55 @@
#!/bin/bash #!/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 # See comments in install script
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve app settings # Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain) 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) is_public=$(ynh_app_setting_get "$app" is_public)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Check final_path directory if [ "$is_public" = "Yes" ]; then
final_path=/var/www/$app ynh_app_setting_set $app is_public 1 # Fix is_public as a boolean value
[[ ! -d $final_path ]] && ynh_die \ is_public=1
"The destination directory '$final_path' does not exist.\ elif [ "$is_public" = "No" ]; then
The app is not correctly installed, you should remove it first." 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 # Move old app dir
sudo mv ${final_path} ${final_path}.old sudo mv ${final_path} ${final_path}.old
# Copy source files # Download, check integrity, uncompress and patch the source from app.src
sudo mkdir -p $final_path ynh_setup_source "$final_path"
# Get source
SETUP_SOURCE
# restore data # restore data
sudo cp -a ${final_path}.old/data ${final_path} 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) # you may need to make some file and/or directory writeable by www-data (nginx user)
sudo chown -R root: $final_path sudo chown -R root: $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory # Create a dedicated nginx config
nginx_conf=../conf/nginx.conf ynh_add_nginx_config
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
### PHP (remove if not used) ### ### PHP (remove if not used) ###
# If a dedicated php-fpm process is 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 # sudo service php5-fpm restart
### PHP end ### ### PHP end ###
# If app is public, add url to SSOWat conf as skipped_uris #=================================================
if [[ $is_public -eq 1 ]]; then # SETUP SSOWAT
# See install script #=================================================
ynh_app_setting_set "$app" unprotected_uris "/"
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 fi
sudo chmod -R 777 $final_path/data sudo chmod -R 777 $final_path/data
# Reload nginx service #=================================================
sudo service nginx reload # RELOAD NGINX
#=================================================
systemctl reload nginx