mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Do not fail on backup and restore if some missing files are not mandatory (#576)
This commit is contained in:
parent
fa5a226339
commit
08818757cc
1 changed files with 21 additions and 10 deletions
|
@ -10,12 +10,13 @@ CAN_BIND=${CAN_BIND:-1}
|
|||
#
|
||||
# If DEST is ended by a slash it complete this path with the basename of SRC.
|
||||
#
|
||||
# usage: ynh_backup src [dest [is_big [arg]]]
|
||||
# usage: ynh_backup src [dest [is_big [not_mandatory [arg]]]]
|
||||
# | arg: src - file or directory to bind or symlink or copy. it shouldn't be in
|
||||
# the backup dir.
|
||||
# | arg: dest - destination file or directory inside the
|
||||
# backup dir
|
||||
# | arg: is_big - 1 to indicate data are big (mail, video, image ...)
|
||||
# | arg: not_mandatory - 1 to indicate that if the file is missing, the backup can ignore it.
|
||||
# | arg: arg - Deprecated arg
|
||||
#
|
||||
# example:
|
||||
|
@ -46,6 +47,7 @@ ynh_backup() {
|
|||
local SRC_PATH="$1"
|
||||
local DEST_PATH="${2:-}"
|
||||
local IS_BIG="${3:-0}"
|
||||
local NOT_MANDATORY="${4:-0}"
|
||||
BACKUP_CORE_ONLY=${BACKUP_CORE_ONLY:-0}
|
||||
|
||||
# If backing up core only (used by ynh_backup_before_upgrade),
|
||||
|
@ -60,15 +62,17 @@ ynh_backup() {
|
|||
# ==============================================================================
|
||||
# Be sure the source path is not empty
|
||||
[[ -e "${SRC_PATH}" ]] || {
|
||||
echo "!!! Source path '${SRC_PATH}' does not exist !!!" >&2
|
||||
|
||||
# This is a temporary fix for fail2ban config files missing after the migration to stretch.
|
||||
if echo "${SRC_PATH}" | grep --quiet "/etc/fail2ban"
|
||||
if [ "$NOT_MANDATORY" == "0" ]
|
||||
then
|
||||
touch "${SRC_PATH}"
|
||||
echo "The missing file will be replaced by a dummy one for the backup !!!" >&2
|
||||
# This is a temporary fix for fail2ban config files missing after the migration to stretch.
|
||||
if echo "${SRC_PATH}" | grep --quiet "/etc/fail2ban"
|
||||
then
|
||||
touch "${SRC_PATH}"
|
||||
echo "The missing file will be replaced by a dummy one for the backup !!!" >&2
|
||||
else
|
||||
return 1
|
||||
else
|
||||
return 1
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -176,12 +180,13 @@ with open(sys.argv[1], 'r') as backup_file:
|
|||
# Use the registered path in backup_list by ynh_backup to restore the file at
|
||||
# the good place.
|
||||
#
|
||||
# usage: ynh_restore_file ORIGIN_PATH [ DEST_PATH ]
|
||||
# usage: ynh_restore_file ORIGIN_PATH [ DEST_PATH [NOT_MANDATORY]]
|
||||
# | arg: ORIGIN_PATH - Path where was located the file or the directory before
|
||||
# to be backuped or relative path to $YNH_CWD where it is located in the backup archive
|
||||
# | arg: DEST_PATH - Path where restore the file or the dir, if unspecified,
|
||||
# the destination will be ORIGIN_PATH or if the ORIGIN_PATH doesn't exist in
|
||||
# the archive, the destination will be searched into backup.csv
|
||||
# | arg: NOT_MANDATORY - 1 to indicate that if the file is missing, the restore process can ignore it.
|
||||
#
|
||||
# If DEST_PATH already exists and is lighter than 500 Mo, a backup will be made in
|
||||
# /home/yunohost.conf/backup/. Otherwise, the existing file is removed.
|
||||
|
@ -201,10 +206,16 @@ ynh_restore_file () {
|
|||
local ARCHIVE_PATH="$YNH_CWD${ORIGIN_PATH}"
|
||||
# Default value for DEST_PATH = /$ORIGIN_PATH
|
||||
local DEST_PATH="${2:-$ORIGIN_PATH}"
|
||||
local NOT_MANDATORY="${3:-0}"
|
||||
|
||||
# If ARCHIVE_PATH doesn't exist, search for a corresponding path in CSV
|
||||
if [ ! -d "$ARCHIVE_PATH" ] && [ ! -f "$ARCHIVE_PATH" ] && [ ! -L "$ARCHIVE_PATH" ]; then
|
||||
ARCHIVE_PATH="$YNH_BACKUP_DIR/$(_get_archive_path \"$ORIGIN_PATH\")"
|
||||
if [ "$NOT_MANDATORY" == "0" ]
|
||||
then
|
||||
ARCHIVE_PATH="$YNH_BACKUP_DIR/$(_get_archive_path \"$ORIGIN_PATH\")"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Move the old directory if it already exists
|
||||
|
|
Loading…
Add table
Reference in a new issue