X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=freeze-dir.sh;fp=freeze-dir.sh;h=5ae7015e46436a31e8f6de12dd29462337a1add5;hb=006eaa8bf4b02876c790e0a4b1d8d7871c91d801;hp=0000000000000000000000000000000000000000;hpb=d9930e7823c007964a023880587f23db98754eb8;p=scripts.git
diff --git a/freeze-dir.sh b/freeze-dir.sh
new file mode 100755
index 0000000..5ae7015
--- /dev/null
+++ b/freeze-dir.sh
@@ -0,0 +1,75 @@
+#!/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 . #
+# #
+# Written by and Copyright (C) Francois Fleuret #
+# Contact 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