From 006eaa8bf4b02876c790e0a4b1d8d7871c91d801 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 6 Nov 2015 10:01:02 +0100 Subject: [PATCH] Update. --- freeze-dir.sh | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 freeze-dir.sh 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 -- 2.39.5