diff --git a/scripts/backup b/scripts/backup index 772fae0..6bdb069 100644 --- a/scripts/backup +++ b/scripts/backup @@ -35,4 +35,18 @@ ynh_backup "/etc/systemd/system/${app}.service" ynh_backup "/var/log/$app" # Dump the database -ynh_mysql_dump_db "$dbname" > ./db.sql \ No newline at end of file +ynh_mysql_dump_db "$dbname" > ./db.sql + + +#================================================= +# BACKUP THE DATA DIRECTORY +#================================================= + +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 "/home/$app" +else + echo "Data dir will not be saved, because backup_core_only is set." >&2 +fi \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index c13cf0d..47952ac 100644 --- a/scripts/restore +++ b/scripts/restore @@ -43,10 +43,46 @@ test getent passwd "$app" &>/dev/null || \ # Should be replaced by this when getops is available in the helper ynh_system_user_create (probably in Yunohost 3.5) # ynh_system_user_create --username= $app --home_dir=/opt/yunohost/$app --use_shell -# Restore all files -ynh_restore -# Create and restore the database +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= + +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" + +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_restore_file "/etc/logrotate.d/$app" + +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= +ynh_restore_file "$final_path" + +#================================================= +# RESTORE DATADIR +#================================================= +# Restore all files +datadir="/home/${app}" + +# 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/home/$app" ] +then + ynh_restore_file "$datadir" +else + # Create app folders + mkdir -p "$datadir" +fi +# Remove the option backup_core_only if it's in the settings.yml file +ynh_app_setting_delete $app backup_core_only + + +#================================================= +# RESTORE DATABASE +#================================================= ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass" ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql diff --git a/scripts/upgrade b/scripts/upgrade index ed849fc..9d568e5 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,6 +24,8 @@ is_public=$(ynh_app_setting_get "$app" is_public) port=$(ynh_app_setting_get "$app" web_port) # Backup the current version of the app +# Inform the backup/restore process that it should not save the data directory +ynh_app_setting_set $app backup_core_only 1 ynh_backup_before_upgrade ynh_clean_setup () { ynh_restore_upgradebackup