This commit is contained in:
2021-01-31 23:15:57 +01:00
parent 80d83da69b
commit c4589ad22d
11 changed files with 1382 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
readonly USAGE="
USAGE:
$(basename "$0") [FILE]"
function help_message() {
echo "$USAGE"
}
# check if there is any parameter
if [ "$#" -ne 1 ]; then
help_message
exit 0
fi
# check if the parameter is valid
if ! test -f "$1"; then
echo "File $1 does not exist."
exit 0
fi
# variables
readonly FILE_DIR="$(cd "$(dirname "$1")" && pwd)"
readonly FILE="$(basename "$1")"
OLD_DATE="$(date -r "$1" "+%Y-%m-%d_%H:%M:%S")"
cp "${FILE_DIR}/${FILE}" "${FILE_DIR}/${FILE}.${OLD_DATE}"
if ! test -f "${FILE_DIR}/${FILE}.tar"; then
tar -C "${FILE_DIR}" -cf "${FILE_DIR}/${FILE}.tar" "${FILE}.${OLD_DATE}"
echo "File ${FILE}.tar created."
echo "${FILE}.${OLD_DATE}"
else
tar -C "${FILE_DIR}" -rf "${FILE_DIR}/${FILE}.tar" "${FILE}.${OLD_DATE}"
echo "${FILE}.${OLD_DATE}"
fi
rm "${FILE_DIR}/${FILE}.${OLD_DATE}"
while true; do
sleep 5
DATE="$(date -r "$1" "+%Y-%m-%d_%H:%M:%S")"
if [ "$DATE" != "$OLD_DATE" ]; then
echo "${FILE}.${DATE}"
cp "${FILE_DIR}/${FILE}" "${FILE_DIR}/${FILE}.${DATE}"
tar -C "${FILE_DIR}" -rf "${FILE_DIR}/${FILE}.tar" "${FILE}.${DATE}"
rm "${FILE_DIR}/${FILE}.${DATE}"
OLD_DATE=$DATE
fi
done