Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more safely remove for move away functionality #784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion usr/share/rear/conf/default.conf
Expand Up @@ -802,13 +802,19 @@ readonly BACKUP_RESTORE_MOVE_AWAY_DIRECTORY="$VAR_DIR/moved_away_after_backup_re
# so that it can be modified as needed by the scripts.
# The items in the BACKUP_RESTORE_MOVE_AWAY_FILES list do not need to be only files.
# Also a whole directory tree can be moved away (automatically recursively).
# If an item in BACKUP_RESTORE_MOVE_AWAY_FILES is a directory only its content
# is (recursively) removed but the original (empty) directory is kept because
# the empty directory alone should not cause issues and usually only the content
# is what results wrong/outdated content that conflicts with the actual system
# or what is no longer needed after system recovery (e.g. content in /var/tmp
# is probably no longer needed but the /var/tmp directory is still needed).
# Already existing stuff in the BACKUP_RESTORE_MOVE_AWAY_DIRECTORY that would be (partially)
# overwritten by the items in the BACKUP_RESTORE_MOVE_AWAY_FILES list is removed before
# (because such stuff is considered as outdated leftover e.g. from a previous recovery)
# but already existing stuff in the BACKUP_RESTORE_MOVE_AWAY_DIRECTORY that is not
# in the curent BACKUP_RESTORE_MOVE_AWAY_FILES list is kept.
# Example:
# Perhaps stuff in the /var/tmp directory is not needed after a system recovery
# Probably stuff in the /var/tmp directory is not needed after a system recovery
# and /etc/udev/rules.d/70-persistent-net.rules is created and maintained
# by systemd/udev (see https://github.com/rear/rear/issues/770):
# BACKUP_RESTORE_MOVE_AWAY_FILES=( /var/tmp /etc/udev/rules.d/70-persistent-net.rules )
Expand Down
18 changes: 16 additions & 2 deletions usr/share/rear/restore/default/99_move_away_restored_files.sh
Expand Up @@ -57,8 +57,22 @@ for dummy in "once" ; do
# but keep already existing stuff in the move away directory
# that is not in the curent BACKUP_RESTORE_MOVE_AWAY_FILES list:
rm -rf $move_away_dir/$file_relative
# Only if the copy was successful remove the original file or directory:
cp -a --parents $file_relative $move_away_dir && rm -rf $file_relative
# Copy the file or directory:
cp -a --parents $file_relative $move_away_dir || continue
# Only if the copy was successful remove the original file or directory content
# but keep the original (empty) directory (for the reason see default.conf):
if test -d $file_relative ; then
# remove all files in the directory other than '.' and '..'
# (avoids scaring stderr message: "rm: refusing to remove '.' or '..' directory")
# * matches non-dot-files
# .[!.]* matches dot-files except '.' and dot-dot-files
# ..?* matches dot-dot-files (also dot-dot-...-dot-files) except '..'
# If all patterns match nothing the nullglob setting in rear let it expand to empty
# which is o.k. because 'rm -f' does not care about non-existent arguments:
rm -rf $file_relative/* $file_relative/.[!.]* $file_relative/..?*
else
rm -rf $file_relative
fi
done
done
# Go back from the recovery system root directory:
Expand Down