backup/restore for both root and subdir

This commit is contained in:
Kay0u 2020-12-24 18:39:32 +01:00
parent a45b22132c
commit a4c0a3fcc4
No known key found for this signature in database
GPG key ID: AE1DCADB6415A156
2 changed files with 82 additions and 66 deletions

View file

@ -452,74 +452,86 @@ TEST_BACKUP_RESTORE () {
# Check if an install have previously work # Check if an install have previously work
at_least_one_install_succeeded || return 1 at_least_one_install_succeeded || return 1
local check_path="$(default_install_path)" local check_paths=()
# Install the application in a LXC container if this_is_a_web_app; then
_LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path" there_is_a_root_install_test && check_paths+=("$(root_path)")
there_is_a_subdir_install_test && check_paths+=("$(subdir_path)")
local ret=$? else
check_paths+=("")
fi
local main_result=0 local main_result=0
# Remove the previous residual backups for check_path in "${check_paths[@]}"
RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives
# BACKUP
# Made a backup if the installation succeed
if [ $ret -ne 0 ]
then
log_error "Installation failed..."
else
log_small_title "Backup of the application..."
# Made a backup of the application
_RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id"
ret=$?
fi
[ $ret -eq 0 ] || main_result=1
# Grab the backup archive into the LXC container, and keep a copy
lxc file pull -r $LXC_NAME/home/yunohost.backup/archives $TEST_CONTEXT/ynh_backups
# RESTORE
# Try the restore process in 2 times, first after removing the app, second after a restore of the container.
local j=0
for j in 0 1
do do
# First, simply remove the application # Install the application in a LXC container
if [ $j -eq 0 ] _LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path"
then
# Remove the application
_REMOVE_APP
log_small_title "Restore after removing the application..."
# Second, restore the whole container to remove completely the application
elif [ $j -eq 1 ]
then
LOAD_LXC_SNAPSHOT snap0
# Remove the previous residual backups
RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives
# Place the copy of the backup archive in the container.
lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/
_PREINSTALL
log_small_title "Restore on a fresh YunoHost system..."
fi
# Restore the application from the previous backup
_RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path"
local ret=$? local ret=$?
# Remove the previous residual backups
RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives
# BACKUP
# Made a backup if the installation succeed
if [ $ret -ne 0 ]
then
log_error "Installation failed..."
main_result=1
continue
else
log_small_title "Backup of the application..."
# Made a backup of the application
_RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id"
ret=$?
fi
[ $ret -eq 0 ] || main_result=1 [ $ret -eq 0 ] || main_result=1
break_before_continue # Grab the backup archive into the LXC container, and keep a copy
lxc file pull -r $LXC_NAME/home/yunohost.backup/archives $TEST_CONTEXT/ynh_backups
# RESTORE
# Try the restore process in 2 times, first after removing the app, second after a restore of the container.
local j=0
for j in 0 1
do
# First, simply remove the application
if [ $j -eq 0 ]
then
# Remove the application
_REMOVE_APP
log_small_title "Restore after removing the application..."
# Second, restore the whole container to remove completely the application
elif [ $j -eq 1 ]
then
LOAD_LXC_SNAPSHOT snap0
# Remove the previous residual backups
RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives
# Place the copy of the backup archive in the container.
lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/
_PREINSTALL
log_small_title "Restore on a fresh YunoHost system..."
fi
# Restore the application from the previous backup
_RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \
&& _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path"
ret=$?
[ $ret -eq 0 ] || main_result=1
break_before_continue
done
done done
return $main_result return $main_result

View file

@ -403,15 +403,19 @@ this_is_a_web_app () {
return $(there_is_a_root_install_test) || $(there_is_a_subdir_install_test) return $(there_is_a_root_install_test) || $(there_is_a_subdir_install_test)
} }
root_path () {
echo "/"
}
subdir_path () {
echo "/path"
}
default_install_path() { default_install_path() {
# All webapps should be installable at the root or in a subpath of a domain # All webapps should be installable at the root or in a subpath of a domain
if there_is_a_root_install_test; then there_is_a_root_install_test && { root_path; return; }
echo "/" there_is_a_subdir_install_test && { subdir_path; return; }
elif there_is_a_subdir_install_test; then echo ""
echo "/path"
else
echo ""
fi
} }
path_to_install_type() { path_to_install_type() {