1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/freshrss_ynh.git synced 2024-09-03 18:36:33 +02:00

refactor backup / restore process

This commit is contained in:
Clément 2019-02-21 08:06:28 +01:00
parent e1644d609e
commit 6afc365e3e
2 changed files with 148 additions and 43 deletions

View file

@ -1,7 +1,13 @@
#!/bin/bash #!/bin/bash
# Source app helpers #=================================================
. /usr/share/yunohost/helpers # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
@ -10,18 +16,57 @@
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
# retrieve useful param #=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
path=/var/www/$app
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
domain=$(ynh_app_setting_get "$app" domain)
# Backup app files final_path=$(ynh_app_setting_get $app final_path)
ynh_backup "$path" "www" domain=$(ynh_app_setting_get $app domain)
# Backup conf files db_name=$(ynh_app_setting_get $app db_name)
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf"
ynh_backup "/etc/cron.d/$app" "cron"
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" "php-fpm.conf"
# Backup mysql #=================================================
ynh_mysql_dump_db $app > $app.dmp # STANDARD BACKUP STEPS
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_print_info "Backing up the main app directory..."
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backing up nginx web server configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Backing up php-fpm configuration..."
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info "Backing up the MySQL database..."
ynh_mysql_dump_db "$db_name" > db.sql
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP A CRON FILE
#=================================================
ynh_backup "/etc/cron.d/$app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -6,53 +6,113 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_print_info "Loading settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
db_user=$app
db_name=$app
# retrieve useful param
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)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
# Check web path availability #=================================================
ynh_webpath_available $domain $path # CHECK IF THE APP CAN BE RESTORED
# Register (book) web path #=================================================
ynh_webpath_register $app $domain $path ynh_print_info "Validating restoration parameters..."
db_pass=$(ynh_app_setting_get $app mysqlpwd) ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#install php dependencies if necessary #=================================================
install_freshrss_dependencies # STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info "Restoring the app main directory..."
# Restore sources & data
final_path=/var/www/$app
ynh_restore_file "$final_path" ynh_restore_file "$final_path"
# Restore permissions #=================================================
sudo chown -R root:root $final_path # RECREATE THE DEDICATED USER
sudo chown -R www-data: $final_path/data/ #=================================================
sudo chown -R www-data: $final_path/extensions/ ynh_print_info "Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R root: $final_path
chown -R $app: $final_path/data/
chown -R $app: $final_path/extensions/
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
# Restore conf files
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file "/etc/cron.d/$app"
ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
# Restore mysql dump #=================================================
ynh_mysql_create_db "$db_name" "$db_user" "$db_pass" # SPECIFIC RESTORATION
ynh_mysql_connect_as "$db_user" "$db_pass" "$db_name" < "$app.dmp" #=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info "Reinstalling dependencies..."
# Reload Nginx, and regenerate SSOwat conf # Define and install dependencies
sudo service nginx reload ynh_install_app_dependencies $pkg_dependencies
sudo service php7.0-fpm reload
sudo yunohost app ssowatconf #=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_print_info "Restoring 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
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file "/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_print_info "Reloading nginx web server and php-fpm..."
systemctl reload php7.0-fpm
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Restoration completed for $app"