X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=scripts.git;a=blobdiff_plain;f=freeze-dir.sh;h=0a23b494fdc2cc86162bde1bab5db1a9872caf60;hp=14c3070a6f7c4bc27801f1946160aaf649621f04;hb=c959baab4f9a2ba5b483a20336ef74b01704c6f7;hpb=0acec4f7f3292ea19e685c70ce9b300f0fe9c9c2 diff --git a/freeze-dir.sh b/freeze-dir.sh index 14c3070..0a23b49 100755 --- a/freeze-dir.sh +++ b/freeze-dir.sh @@ -18,13 +18,16 @@ ######################################################################### # This command makes a backup copy of a given directory into a backup -# directory, tags it with the date and time, and uses rsync -# intelligent features to avoid making superfluous copies of files -# which are already backuped. +# directory, tags it with the date and time, and uses rsync smart use +# of hard links to avoid unnecessary duplicates of files already +# backuped. set -e -[[ ${FREEZE_DIR} ]] || FREEZE_DIR=${HOME}/.backups +# The default directory does not start with a period, as it may be +# huge and should not be "hidden" from the user. + +[[ ${FREEZE_DIR} ]] || FREEZE_DIR=${HOME}/freezer if [[ ! -d ${FREEZE_DIR} ]]; then echo "Can not find directory ${FREEZE_DIR}" >&2 @@ -32,9 +35,9 @@ if [[ ! -d ${FREEZE_DIR} ]]; then fi while [[ "$1" ]]; do - - dir=$(basename "$1") - path=$(dirname "$1") + real_path="$(realpath "$1")" + dir=$(basename "${real_path}") + path=$(dirname "${real_path}") full_path="${path}/${dir}" date=$(date +%Y_%b_%d_%H:%M:%S) @@ -59,7 +62,7 @@ while [[ "$1" ]]; do if [[ -h "${current_backup}" ]]; then rsync --link-dest="${current_backup}/" -axz "${full_path}/" "${new_backup}/" - rm -f "${current_backup}" + rm "${current_backup}" else if [[ -a ${current_backup} ]]; then echo "${current_backup} exists and is not a symbolic link" >&2 @@ -69,7 +72,7 @@ while [[ "$1" ]]; do fi fi - ln -s "${new_backup}" "${current_backup}" + ln -vs "${new_backup}" "${current_backup}" sync