X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=freeze-dir.sh;h=d8b249d98d31f70e2a9d61523d6615f28ca96167;hb=9a5a6e9982b31d81af59d9210e5938e50a72f855;hp=5ae7015e46436a31e8f6de12dd29462337a1add5;hpb=006eaa8bf4b02876c790e0a4b1d8d7871c91d801;p=scripts.git diff --git a/freeze-dir.sh b/freeze-dir.sh index 5ae7015..d8b249d 100755 --- a/freeze-dir.sh +++ b/freeze-dir.sh @@ -17,9 +17,17 @@ # Contact for comments & bug reports # ######################################################################### +# This command makes a backup copy of a given directory into a backup +# 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 @@ -27,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) @@ -53,18 +61,18 @@ while [[ "$1" ]]; do new_backup="${backup}:::${date}" if [[ -h "${current_backup}" ]]; then - rsync --link-dest="${current_backup}/" -axz "${full_path}/" "${new_backup}/" - rm -f "${current_backup}" + rsync --progress --link-dest="${current_backup}/" -axz "${full_path}/" "${new_backup}/" + rm "${current_backup}" else if [[ -a ${current_backup} ]]; then echo "${current_backup} exists and is not a symbolic link" >&2 exit 1 else - rsync -axz "${full_path}/" "${new_backup}/" + rsync --progress -axz "${full_path}/" "${new_backup}/" fi fi - ln -s "${new_backup}" "${current_backup}" + ln -vs "${new_backup}" "${current_backup}" sync