diff --git a/borg2-backup.sh b/borg2-backup.sh index a74930c..ba8eef8 100755 --- a/borg2-backup.sh +++ b/borg2-backup.sh @@ -6,7 +6,9 @@ working_dir="$(dirname $(realpath $0))" conf_file="${working_dir}/conf/${script_name%%.*}.conf" LOCK_DIR="/tmp/${script_name%%.*}.LOCK" -log_file="${LOCK_DIR}/${script_name%%.*}.log" +#log_file="${LOCK_DIR}/${script_name%%.*}.log" + +lock_file="${LOCK_DIR}/${script_name%%.*}.log" backup_date="$(date +%Y-%m-%d-%H%M)" @@ -354,9 +356,13 @@ done # BORG_BACKUP_DIRS="${BORG_BACKUP_DIRS#"${BORG_BACKUP_DIRS%%[![:space:]]*}"}" -BORG_URL="ssh://${SSH_USER}@${BORG_HOST}:${SSH_PORT}${BORG_REPO}" +if [[ "${BORG_HOST,,}" == "localhost" ]] ; then + BORG_URL="file://${BORG_REPO}" +else + BORG_URL="ssh://${SSH_USER}@${BORG_HOST}:${SSH_PORT}${BORG_REPO}" +fi -#BORG_REPO="${BORG_URL}" +export BORG_REPO="${BORG_URL}" ARCHIVE_NAME="${backup_date}" @@ -848,6 +854,73 @@ fi blank_line +#echononl "Erstelle Lock Datei '$(basename "${lock_file}")' .." +#touch "${lock_file}" > "${log_file}" +# +#if [[ $? -gt 0 ]] ; then +# echo_failed +#else +# echo_ok +#fi +# +#echononl "Starte Hintergrundroutine - prüfe Existenz von borg2 lock dateien." +#( +# #echo "Lock-Watcher gestartet..." +# +# declare -i index=0 +# +# # Solange die eigene Lockdatei existiert +# while [ -e "${lock_file}" ]; do +# +# # Nur vor dem 1. durchlauf warten.. +# [[ ${index} -lt 1 ]] && sleep 10 +# +# declare -i deleted_something=0 +# +# # Zielpfade +# LOCK_DIR="/mnt/backup/BORG-2/file-ah/lock.exclusive/lock.exclusive" +# LOCK_FILE="/mnt/backup/BORG-2/file-ah/lock.roster" +# +# # Falls das Verzeichnis existiert, löschen +# if [ -d "$LOCK_DIR" ]; then +# #echo "Verzeichnis $LOCK_DIR gefunden - wird gelöscht..." +# rm -rf "$LOCK_DIR" +# deleted_something=1 +# fi +# +# # Falls die Datei existiert, löschen +# if [ -f "$LOCK_FILE" ]; then +# #echo "Datei $LOCK_FILE gefunden - wird gelöscht..." +# rm -f "$LOCK_FILE" +# deleted_something=1 +# fi +# +# # Wenn etwas gelöscht wurde: eigene Lockdatei löschen und abbrechen +# if [ "$deleted_something" -eq 1 ]; then +# if [ -e "${lock_file}" ]; then +# #echo "Eigene Lockdatei $MY_LOCKFILE wird gelöscht..." +# rm -f "${lock_file}" +# fi +# #echo "Lock-Watcher beendet Löschung erfolgt." +# exit 0 +# fi +# +# # Kurze Pause, um Systemlast zu minimieren (z.B. alle 5 Sekunden prüfen) +# sleep 20 +# +# (( index++ )) +# done +# +# #echo "Lock-Watcher beendet Lockdatei $MY_LOCKFILE existiert nicht mehr." +#) & +# +#echo_done +# +#sleep 5 +# +# +#blank_line + echononl "Create borg backup.." @@ -855,7 +928,6 @@ echononl "Create borg backup.." cat << EOF >> ${BORG_LOG_FILE} borg2 \\ --remote-path borg2 \\ - --repo ${BORG_URL} \\ create \\ --verbose \\ --filter AME \\ @@ -883,7 +955,6 @@ EOF borg2 \ --remote-path borg2 \ - --repo ${BORG_URL} \ create \ --verbose \ --filter AME \ @@ -904,14 +975,15 @@ borg2 \ --exclude '**/sessions/*' \ --exclude '**/*.20[2-3][0-9]-[0-1][0-9]*' \ ${ARCHIVE_NAME} \ - ${BORG_BACKUP_DIRS} ${BACKUP_NET_DIRECTORIES} \ - ${DB_BACKUP_DIR} \ - > ${log_file} 2>&1 + ${BORG_BACKUP_DIRS} ${BACKUP_NET_DIRECTORIES} ${DB_BACKUP_DIR} 2>> ${log_file} -if [[ $? -gt 0 ]] ; then +declare -i _ret_val=$? + +if [[ ${_ret_val} -gt 0 ]] ; then echo_failed - error "$(cat "${log_file}")" + cat ${log_file} >> "${BORG_LOG_FILE}" + error "_ret_val: ${_ret_val}\n$(cat "${log_file}")" else echo_ok cat ${log_file} >> ${BORG_LOG_FILE} @@ -923,7 +995,6 @@ echononl "Pruning repository.." cat << EOF >> ${BORG_LOG_FILE} borg2 \\ --remote-path borg2 \\ - --repo ${BORG_URL} \\ prune \\ --list \\ --show-rc \\ @@ -933,9 +1004,9 @@ borg2 \\ --keep-yearly ${KEEP_YEARLY} \\ EOF + borg2 \ --remote-path borg2 \ - --repo ${BORG_URL} \ prune \ --list \ --show-rc \ @@ -945,6 +1016,7 @@ borg2 \ --keep-yearly ${KEEP_YEARLY} \ > ${log_file} 2>&1 + if [[ $? -gt 0 ]] ; then echo_failed error "$(cat "${log_file}")" @@ -958,16 +1030,18 @@ echononl "Free repository space by deleting unused chunks..." cat << EOF >> ${BORG_LOG_FILE} borg2 \\ --remote-path borg2 \\ - --repo ${BORG_URL} \\ compact EOF +# --repo ${BORG_URL} \\ + borg2 \ --remote-path borg2 \ - --repo ${BORG_URL} \ compact \ > ${log_file} 2>&1 +# --repo ${BORG_URL} \ + if [[ $? -gt 0 ]] ; then echo_failed error "$(cat "${log_file}")"