--- /dev/null
+#!/bin/bash
+
+#########################################################################
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the version 3 of the GNU General Public License #
+# as published by the Free Software Foundation. #
+# #
+# This program is distributed in the hope that it will be useful, but #
+# WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
+# General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+# Written by and Copyright (C) Francois Fleuret #
+# Contact <francois@fleuret.org> for comments & bug reports #
+#########################################################################
+
+set -e
+
+[[ ${FREEZE_DIR} ]] || FREEZE_DIR=${HOME}/.backups
+
+if [[ ! -d ${FREEZE_DIR} ]]; then
+ echo "Can not find directory ${FREEZE_DIR}" >&2
+ exit 1
+fi
+
+while [[ "$1" ]]; do
+
+ dir=$(basename "$1")
+ path=$(dirname "$1")
+ full_path="${path}/${dir}"
+
+ date=$(date +%Y_%b_%d_%H:%M:%S)
+
+ if [[ ! -d "${full_path}" ]]; then
+ echo "Can not find directory ${full_path}" >&2
+ exit 1
+ fi
+
+ if [[ $(find "${full_path}" -type f -name "core*" -o -name "vgcore.[0-9]*") ]]; then
+ # rm -i $(find "${full_path}" -type f -name "core" -o -name "vgcore.[0-9]*")
+ echo "There seems to be core files in ${full_path}" >&2
+ exit 1
+ fi
+
+ backup="${FREEZE_DIR}/${full_path}"
+
+ mkdir -p "${FREEZE_DIR}/${path}"
+
+ current_backup="${backup}:::current"
+ new_backup="${backup}:::${date}"
+
+ if [[ -h "${current_backup}" ]]; then
+ rsync --link-dest="${current_backup}/" -axz "${full_path}/" "${new_backup}/"
+ rm -f "${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}/"
+ fi
+ fi
+
+ ln -s "${new_backup}" "${current_backup}"
+
+ sync
+
+ du -sh "${new_backup}"
+
+ shift
+
+done