7 Commits

Author SHA1 Message Date
Olli Graf
d1d4d01eb6 status=progress bei dd gesetzt. 2024-11-08 09:35:19 +01:00
Olli Graf
09e4e1c8fe Blocksize wieder auf 8M erhöht. 2024-11-04 08:32:59 +01:00
Olli Graf
42d386c42d sha256 Datei wird am Ende wieder gelöscht.
prgerepo.sh löscht alles bis auf die letzten drei Backups.
2024-11-04 07:17:51 +01:00
Olli Graf
ae357b49bb Versionsnummer 2024-11-03 14:38:48 +01:00
Olli Graf
bc029140fe Repo Dir wird automatisch angelegt, falls nicht existent. 2024-11-03 14:37:41 +01:00
Olli Graf
b43444d441 Zweiter Aufrufparameter ist jetzt der Hostname des Pis.
Der Dateiname derBackupdatei wird selbstständig mit Datum zusammengebaut.
2023-10-08 14:49:15 +02:00
Olli Graf
23979a0859 rmoldest in purgerepo umbenannt. 2023-09-29 07:20:34 +02:00
5 changed files with 53 additions and 34 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
backup.img

View File

@@ -1,11 +1,27 @@
#! /bin/bash #! /bin/bash
VERSION="1.00" BACKUP_REPO="/tank/Backup-Repo"
TEMP_DIR="${HOME}/backup"
VERSION="2.02"
CMD_COMPRESS='pbzip2' CMD_COMPRESS='pbzip2'
verbose=false verbose=false
testmode=false testmode=false
bzip2=false bzip2=false
if [ $# -ne 2 ]
then
echo "Usage: backupsd <src_device> <target_file>"
echo "Please try again."
exit 1
fi
if !command -v dd > /dev/null 2>&1
then
echo "required command dd is not installed."
echo " Please check."
exit 2
fi
function isolate_checksum() { function isolate_checksum() {
checksum=($(echo ${1} | tr " " "\n"[0])) checksum=($(echo ${1} | tr " " "\n"[0]))
@@ -13,30 +29,26 @@ checksum=($(echo ${1} | tr " " "\n"[0]))
echo "${checksum}" echo "${checksum}"
} }
function format_date() {
tdate=$(date '+%y-%m-%d')
echo "${tdate}"
}
function start_backup { function start_backup {
echo "starting Backup" echo "starting Backup"
sudo dd if=${DEVICE} bs=8M|pv| dd of=${FILE} bs=8M sudo dd if=${DEVICE} status=progress bs=8M | 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 "compressing image with ${CMD_COMPRESS}"
echo "sha512dest= ${sha512dest}" ${CMD_COMPRESS} ${FILE}
REPO_DIR="${BACKUP_REPO}/${HOSTNAME}"
if [ "${sha512src}" = "${sha512dest}" ]; then echo "moving compressed image to repo"
echo "compressing image with ${CMD_COMPRESS}" if [ ! -d "${REPO_DIR}" ]; then mkdir "${REPO_DIR}"; fi
${CMD_COMPRESS} ${FILE} FILE="${FILE}.bz2"
exit 0 mv ${FILE} "${BACKUP_REPO}/${HOSTNAME}"
else
echo "checksum verify failed, exiting"
exit 1
fi
} }
@@ -73,7 +85,10 @@ fi
echo "1=${1} 2=${2}" echo "1=${1} 2=${2}"
DEVICE=${1} DEVICE=${1}
FILE=${2} HOSTNAME=${2}
bdate=$(format_date)
echo "bdate=${bdate}"
FILE="${TEMP_DIR}/${HOSTNAME}-${bdate}.img"
#if [[ ${bzip2} -eq true ]] ; then #if [[ ${bzip2} -eq true ]] ; then
#if [[ echo "${bzip2}" |grep "true" ]] ; then #if [[ echo "${bzip2}" |grep "true" ]] ; then
@@ -92,3 +107,6 @@ echo "FILE=${FILE}"
echo "SD-Card Backup ${VERSION}" echo "SD-Card Backup ${VERSION}"
start_backup start_backup
echo "cleaning up..."
rm -v "${TEMP_DIR}/sdcard.sha256"
exit 0

5
formatdate.sh Executable file
View File

@@ -0,0 +1,5 @@
#! /usr/bin/bash
tdate=$(date '+%y-%m-%d')
echo ${tdate}

8
purgerepo.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# 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

View File

@@ -1,13 +0,0 @@
#!/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}"
done