From 42d386c42d5b47477088ff15f52f880e65ff1884 Mon Sep 17 00:00:00 2001 From: Olli Graf Date: Mon, 4 Nov 2024 07:17:51 +0100 Subject: [PATCH] =?UTF-8?q?sha256=20Datei=20wird=20am=20Ende=20wieder=20ge?= =?UTF-8?q?l=C3=B6scht.=20prgerepo.sh=20l=C3=B6scht=20alles=20bis=20auf=20?= =?UTF-8?q?die=20letzten=20drei=20Backups.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + backupsd | 38 +++++++++++++------------------------- formatdate.sh | 5 +++++ purgerepo.sh | 16 +++++----------- 4 files changed, 24 insertions(+), 36 deletions(-) create mode 100644 .gitignore create mode 100755 formatdate.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad871f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +backup.img diff --git a/backupsd b/backupsd index a263d4e..0e3afcb 100755 --- a/backupsd +++ b/backupsd @@ -2,7 +2,7 @@ BACKUP_REPO="/tank/Backup-Repo" TEMP_DIR="${HOME}/backup" -VERSION="1.02" +VERSION="2.01" CMD_COMPRESS='pbzip2' verbose=false testmode=false @@ -37,33 +37,18 @@ tdate=$(date '+%y-%m-%d') function start_backup { echo "starting Backup" -sudo dd if=${DEVICE} bs=8M|pv| dd of=${FILE} bs=8M +sudo dd if=${DEVICE} bs=4M | tee ${FILE} | sha256sum > ${TEMP_DIR}/sdcard.sha256 -echo "verifying..." +echo "validating the image..." -echo "checksum ${DEVICE}" -sha512src=$(sudo sha512sum ${DEVICE}) -sha512src=$(isolate_checksum "${sha512src}") -echo "checksum ${FILE}" -sha512dest=$(sha512sum ${FILE}) -sha512dest=$(isolate_checksum "${sha512dest}") -echo "sha512src= ${sha512src}" -echo "sha512dest= ${sha512dest}" - -if [ "${sha512src}" = "${sha512dest}" ]; then - echo "compressing image with ${CMD_COMPRESS}" - ${CMD_COMPRESS} ${FILE} - REPO_DIR="${BACKUP_REPO}/${HOSTNAME}" - echo "moving compressed image to repo" - if [ ! -d "${REPO_DIR}" ]; then mkdir "${REPO_DIR}"; fi - FILE="${FILE}.bz2" - mv ${FILE} "${BACKUP_REPO}/${HOSTNAME}" - exit 0 -else - echo "checksum verify failed, exiting" - exit 1 -fi +echo "compressing image with ${CMD_COMPRESS}" +${CMD_COMPRESS} ${FILE} +REPO_DIR="${BACKUP_REPO}/${HOSTNAME}" +echo "moving compressed image to repo" +if [ ! -d "${REPO_DIR}" ]; then mkdir "${REPO_DIR}"; fi +FILE="${FILE}.bz2" +mv ${FILE} "${BACKUP_REPO}/${HOSTNAME}" } @@ -122,3 +107,6 @@ echo "FILE=${FILE}" echo "SD-Card Backup ${VERSION}" start_backup +echo "cleaning up..." +rm -v "${TEMP_DIR}/sdcard.sha256" +exit 0 diff --git a/formatdate.sh b/formatdate.sh new file mode 100755 index 0000000..dd15b5e --- /dev/null +++ b/formatdate.sh @@ -0,0 +1,5 @@ +#! /usr/bin/bash + +tdate=$(date '+%y-%m-%d') + +echo ${tdate} diff --git a/purgerepo.sh b/purgerepo.sh index 980fc1b..b3981ef 100755 --- a/purgerepo.sh +++ b/purgerepo.sh @@ -1,14 +1,8 @@ #!/usr/bin/env bash - -files_to_remove=$(find . -maxdepth 1 -type f|cut -c3-|xargs ls -t|tail -3) -echo "eldest files ${files_toremove}" -for backupfile in ${files_to_remove}; do - echo "deleting backup ${backupfile}" - rm -f "${backupfile}" -done - - - - +# Finde alle Dateien im Verzeichnis, sortiere sie nach Änderungszeit, und überspringe die neuesten drei + ls -t | tail -n +4 | while read -r file; do + # Lösche jede Datei, die älter als die drei neuesten ist + rm -v "$file" + done