Protect persistent data during upgrades
This commit is contained in:
parent
6e388019ee
commit
9c42dbdc35
5 changed files with 64 additions and 4 deletions
|
|
@ -12,7 +12,7 @@ Lightweight animal shelter management
|
|||
|
||||
[](https://globinours.fr)
|
||||
[](https://demo.globinours.fr)
|
||||
[?style=for-the-badge)](https://ci-apps.yunohost.org/ci/apps/globinours/)
|
||||
[?style=for-the-badge)](https://ci-apps.yunohost.org/ci/apps/globinours/)
|
||||
|
||||
<div align="center">
|
||||
<a href="https://apps.yunohost.org/app/globinours"><img height="100px" src="https://github.com/YunoHost/yunohost-artwork/raw/refs/heads/main/badges/neopossum-badges/badge_more_info_on_the_appstore.svg"/></a>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ id = "globinours"
|
|||
name = "Globinours"
|
||||
description.en = "Lightweight animal shelter management"
|
||||
description.fr = "Gestion légère et complète pour refuges animaliers"
|
||||
version = "1.0.0-rc.3~ynh14"
|
||||
version = "1.0.0-rc.3~ynh15"
|
||||
maintainers = ["OverSu"]
|
||||
|
||||
[upstream]
|
||||
|
|
|
|||
|
|
@ -15,8 +15,47 @@ install_yunohost_logo() {
|
|||
yunohost user permission update "$app.main" --logo "$logo"
|
||||
}
|
||||
|
||||
migrate_legacy_data() {
|
||||
local legacy_data="$install_dir/data"
|
||||
local legacy_storage="$install_dir/storage"
|
||||
local legacy_media="$install_dir/public/media"
|
||||
|
||||
if [[ -d "$legacy_data" && ! -L "$legacy_data" ]]; then
|
||||
ynh_print_info "Migrating the legacy data directory to $data_dir..."
|
||||
cp -a "$legacy_data/." "$data_dir/"
|
||||
|
||||
if [[ -f "$legacy_data/refuge.sqlite" ]]; then
|
||||
local migrated_database="$data_dir/refuge.sqlite.migrating"
|
||||
sqlite3 "$legacy_data/refuge.sqlite" ".backup '$migrated_database'"
|
||||
|
||||
local integrity_check
|
||||
integrity_check="$(sqlite3 "$migrated_database" "PRAGMA integrity_check;")"
|
||||
if [[ "$integrity_check" != "ok" ]]; then
|
||||
rm -f "$migrated_database"
|
||||
ynh_die --message="The migrated Globinours database failed its integrity check. The legacy data was left untouched."
|
||||
fi
|
||||
|
||||
mv -f "$migrated_database" "$data_dir/refuge.sqlite"
|
||||
rm -f "$data_dir/refuge.sqlite-wal" "$data_dir/refuge.sqlite-shm"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -d "$legacy_storage" && ! -L "$legacy_storage" ]]; then
|
||||
ynh_print_info "Migrating the legacy storage directory to $data_dir/storage..."
|
||||
cp -a "$legacy_storage/." "$data_dir/storage/"
|
||||
fi
|
||||
|
||||
if [[ -d "$legacy_media" && ! -L "$legacy_media" ]]; then
|
||||
ynh_print_info "Migrating the legacy public media directory to $data_dir/media..."
|
||||
cp -a "$legacy_media/." "$data_dir/media/"
|
||||
fi
|
||||
}
|
||||
|
||||
prepare_persistent_paths() {
|
||||
for path_to_replace in "$install_dir/data" "$install_dir/storage" "$install_dir/public/media"; do
|
||||
if [[ -d "$path_to_replace" && ! -L "$path_to_replace" ]]; then
|
||||
ynh_die --message="Refusing to replace the physical data directory $path_to_replace before it is migrated."
|
||||
fi
|
||||
if [[ -e "$path_to_replace" || -L "$path_to_replace" ]]; then
|
||||
ynh_safe_rm "$path_to_replace"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ ynh_script_progression "Restoring system configurations related to $app..."
|
|||
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf"
|
||||
|
||||
migrate_legacy_data
|
||||
|
||||
for migrated_path in "$install_dir/data" "$install_dir/storage" "$install_dir/public/media"; do
|
||||
if [[ -d "$migrated_path" && ! -L "$migrated_path" ]]; then
|
||||
ynh_safe_rm "$migrated_path"
|
||||
fi
|
||||
done
|
||||
|
||||
prepare_persistent_paths
|
||||
install_yunohost_logo
|
||||
ynh_exec_as_app php "$install_dir/scripts/migrate.php"
|
||||
|
|
|
|||
|
|
@ -11,13 +11,19 @@ source /usr/share/yunohost/helpers
|
|||
# CREATE AN APPLICATION BACKUP
|
||||
#=================================================
|
||||
|
||||
if [[ -f "$install_dir/scripts/backup.php" && -f "$data_dir/refuge.sqlite" ]] && \
|
||||
if [[ -f "$install_dir/scripts/backup.php" && -f "$install_dir/data/refuge.sqlite" ]] && \
|
||||
php -l "$install_dir/app/Services/BackupService.php" >/dev/null 2>&1; then
|
||||
ynh_exec_as_app php "$install_dir/scripts/backup.php" pre-upgrade-yunohost
|
||||
elif [[ -f "$data_dir/refuge.sqlite" ]]; then
|
||||
elif [[ -f "$install_dir/data/refuge.sqlite" ]]; then
|
||||
ynh_print_warn --message="La sauvegarde applicative préalable est ignorée car l'ancienne version n'est pas compatible avec PHP $php_version. La sauvegarde de sécurité YunoHost reste active."
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# MIGRATE LEGACY DATA
|
||||
#=================================================
|
||||
|
||||
migrate_legacy_data
|
||||
|
||||
#=================================================
|
||||
# ENABLE MAINTENANCE MODE
|
||||
#=================================================
|
||||
|
|
@ -33,6 +39,13 @@ ynh_script_progression "Upgrading source files..."
|
|||
|
||||
ynh_setup_source --dest_dir="$install_dir" --full_replace --keep="data storage public/media"
|
||||
|
||||
# Physical legacy directories were kept until their migration was complete.
|
||||
for migrated_path in "$install_dir/data" "$install_dir/storage" "$install_dir/public/media"; do
|
||||
if [[ -d "$migrated_path" && ! -L "$migrated_path" ]]; then
|
||||
ynh_safe_rm "$migrated_path"
|
||||
fi
|
||||
done
|
||||
|
||||
#=================================================
|
||||
# UPDATE APPLICATION AND SYSTEM CONFIGURATION
|
||||
#=================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue