1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/calibreweb_ynh.git synced 2024-09-03 18:16:20 +02:00

backup & restore script - init

This commit is contained in:
Krakinou 2018-12-16 17:54:14 +01:00
parent 02259a5356
commit 10968400df
5 changed files with 68 additions and 54 deletions

View file

@ -13,10 +13,6 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -27,8 +23,9 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
path_url=$(ynh_app_setting_get $app path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
calibre_dir=$(ynh_app_setting_get $app calibre_dir)
#=================================================
# STANDARD BACKUP STEPS
@ -59,8 +56,18 @@ ynh_backup "/etc/logrotate.d/$app"
ynh_backup "/etc/systemd/system/$app.service"
#=================================================
# BACKUP A CRON FILE
# BACKUP THE DATA DIRECTORY
#=================================================
ynh_backup "/etc/cron.d/$app"
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
# If backup_core_only have any value in the settings.yml file, do not backup the data directory
if [ -z $backup_core_only ]
then
ynh_backup "calibre_dir"
else
echo "Data dir will not be saved, because backup_core_only is set." >&2
fi

View file

@ -130,13 +130,12 @@ if [ ! -e "$calibre_dir" ]; then
fi
#Check if metadata.db file exists. If not create it (empty library)
if [ ! -e "$calibre_dir"/metadata.db ]; then
cp -a ../src/calibre/. $calibre_dir
cp -a ../conf/metadata.db.empty $calibre_dir/metadata.db
chown $app:$app $calibre_dir/*
fi
# Set permissions to app files
chown -R $app:$app $final_path
chown -R root: $final_path
#=================================================
@ -153,6 +152,7 @@ chown -R $app:$app /var/log/$app
#=================================================
# SET SQLITE DATABASE SETTINGS
#=================================================
ynh_print_info "Setting up database and settings"
#we need to start and stop the service so that initial app.db file is created and that we can set default data
systemctl start $app
@ -173,6 +173,14 @@ sqlite3 $final_path/app.db "UPDATE user SET password='$(python ../conf/generate_
ynh_print_ON
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "${final_path}/app.db"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================

View file

@ -13,10 +13,6 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
#### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
@ -29,7 +25,7 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
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)
calibre_dir=$(ynh_app_setting_get $app calibre_dir)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
@ -67,6 +63,7 @@ ynh_system_user_create $app
# Restore permissions on app files
chown -R root: $final_path
chown calibreweb: $final_path/app.db
#=================================================
# SPECIFIC RESTORATION
@ -75,7 +72,7 @@ chown -R root: $final_path
#=================================================
# Define and install dependencies
ynh_install_app_dependencies deb1 deb2
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
@ -90,11 +87,6 @@ yunohost service add $app --log "/var/log/$app/APP.log"
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_restore_file "/etc/cron.d/$app"
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
@ -103,10 +95,34 @@ ynh_restore_file "/etc/cron.d/$app"
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
# RESTORE THE DATA DIRECTORY
#=================================================
# The data directory will be restored only if it exists in the backup archive
# So only if it was backup previously.
if [ -d "$YNH_BACKUP_DIR/apps/$app/backup/$calibre_dir" ]
then
ynh_restore_file "$calibre_dir"
else
if [ ! -e "$calibre_dir" ]; then
ynh_print_info "Create calibre library folder $calibre_dir"
mkdir -p $calibre_dir
chown -R $app:$app $calibre_dir
fi
#Check if metadata.db file exists. If not create it (empty library)
if [ ! -e "$calibre_dir"/metadata.db ]; then
cp -a ../conf/metadata.db.empty $calibre_dir/metadata.db
chown $app:$app $calibre_dir/*
fi
fi
# Remove the option backup_core_only if it's in the settings.yml file
ynh_app_setting_delete $app backup_core_only
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload php5-fpm
systemctl reload nginx

View file

@ -21,32 +21,8 @@ admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
language=$(ynh_app_setting_get $app language)
db_name=$(ynh_app_setting_get $app db_name)
calibre_dir=$(ynh_app_setting_get $app calibre_dir)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -75,7 +51,12 @@ path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
##as long as v1 is not reached, sha256sum will change without notice so not usable, so we use cp -a instead.
#source are directly in the app so far
#ynh_setup_source "$final_path"
cp -a ../src/calibreweb/. $final_path
#=================================================
# NGINX CONFIGURATION
@ -88,7 +69,8 @@ ynh_add_nginx_config
# UPGRADE DEPENDENCIES
#=================================================
ynh_install_app_dependencies deb1 deb2
ynh_install_app_dependencies $pkg_dependencies
pip install --target $final_path/vendor -r $final_path/requirements.txt
#=================================================
# CREATE DEDICATED USER
@ -106,9 +88,9 @@ ynh_system_user_create $app
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/CONFIG_FILE"
ynh_backup_if_checksum_is_different "$final_path/app.db"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/CONFIG_FILE"
ynh_store_file_checksum "$final_path/app.db"
#=================================================
# SETUP LOGROTATE
@ -132,6 +114,7 @@ ynh_add_systemd_config
# Set permissions on app files
chown -R root: $final_path
chown -R $app: $final_path/app.db
#=================================================
# SETUP SSOWAT