Skip to content

Commit

Permalink
small log refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
per2jensen committed Mar 9, 2024
1 parent ff91c64 commit 4c61ee6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 33 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ This 'dar-backup' package lives at: https://github.com/per2jensen/dar-backup
- sshfs *can* be used to mount remote directory (this was previously hard coded into the script)
- sshfs uses [FUSE](https://www.kernel.org/doc/html/latest/filesystems/fuse.html), allowing a non-privileged user to mount remote storage.
- Logs to a logfile in a user configured directory
- [Log example of a DIFF backup](doc/pics/log-example-01.png) of a single backup definition

- Can save all output to a debug log file, handy if dar exit code is 5 (number files not backed up are listed)
- Status messages can be sent to a Discord hook, change the sendDiscordMsg() function to suit your needs
- Cleanup script removes DIFFs older than 100 days, and INCs older than 40 days. FULL backups are not touched.
Expand Down
6 changes: 3 additions & 3 deletions bin/dar-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,20 @@ exitCodeExpl () {
fi
}

# print a log line if a catalog operation failed somehow
# print a log line with the result of a catalog operation
# set the CATALOG_OK env var if an error happened
# $1: the exit code from manager.sh script
catalogOpsResult () {
local CATALOGRESULT="$1"
case $CATALOGRESULT in
0)
log "${DAR_ARCHIVE} added to it's catalog"
log "${DAR_ARCHIVE} added to it's catalog"
;;
5)
log_warn "Something did not go completely right adding \"${DAR_ARCHIVE}\" to it's catalog"
;;
*)
log_error "Some error were found while adding \"${DAR_ARCHIVE}\" to it's catalog"
log_error "Some error was found while adding \"${DAR_ARCHIVE}\" to it's catalog"
CATALOG_OK=1
;;
esac
Expand Down
36 changes: 6 additions & 30 deletions bin/manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ if [[ $CREATE_CATALOG == "1" ]]; then
if [[ -e "$MOUNT_POINT/$CATALOG" ]]; then
log_warn "\"$MOUNT_POINT/$CATALOG\" already exists, go to next"
else
log "INFO create catalog DB: \"$MOUNT_POINT/$CATALOG\""
log "Create catalog DB: \"$MOUNT_POINT/$CATALOG\""
dar_manager --create "$MOUNT_POINT"/"$CATALOG"
if [[ $? != "0" ]]; then
log_error "something went wrong creating the catalog: \"$MOUNT_POINT/$CATALOG\", continuing..."
Expand All @@ -249,7 +249,7 @@ if [[ $CREATE_CATALOG == "1" ]]; then
log_warn "\"$MOUNT_POINT/$CATALOG\" already exists, exiting"
exit 0
else
log "INFO create catalog DB: \"$MOUNT_POINT/$CATALOG\""
log "Create catalog DB: \"$MOUNT_POINT/$CATALOG\""
dar_manager --create "$MOUNT_POINT"/"$CATALOG"
RESULT=$?
if [[ "$RESULT" != "0" ]]; then
Expand All @@ -276,21 +276,9 @@ if [[ $ADD_DIR == "1" && $ARCHIVE_DIR_TO_ADD != "" ]]; then
do
ARCHIVE="$(basename "${archive}")"
_REALPATH="$(realpath "$MOUNT_POINT"/"$ARCHIVE")"
#log "Add \"$_REALPATH\" to catalog \"$CATALOG\""
dar_manager --base "$MOUNT_POINT/$CATALOG" -ai -Q --add "$_REALPATH"
RESULT=$?
case $RESULT in
0)
log "\"$_REALPATH\" was added to catalog \"$CATALOG\""
;;
5)
log_warn "Some error(s) were found while adding \"${ARCHIVE}\" to it's catalog"
;;
*)
log_error "something went wrong populating \"$MOUNT_POINT/$CATALOG\", dar_manager error: \"$RESULT\""
exit $RESULT
;;
esac
catalogOpsResult "$RESULT" # dar-util.sh
done < <(find "${MOUNT_POINT}" -type f -name "$SEARCHCRIT" -print|grep -E "${CURRENT_BACKUP_DEF}_FULL_.*|${CURRENT_BACKUP_DEF}_DIFF_.*|${CURRENT_BACKUP_DEF}_INC_.*"| grep -E "^.*?[0-9]{4}-[0-9]{2}-[0-9]{2}" -o| sort -u| sort -t "_" -k 3,3)
done < <(find "${SCRIPTDIRPATH}"/../backups.d -type f -print)
else
Expand All @@ -302,21 +290,9 @@ if [[ $ADD_DIR == "1" && $ARCHIVE_DIR_TO_ADD != "" ]]; then
do
ARCHIVE="$(basename "${archive}")"
_REALPATH="$(realpath "$MOUNT_POINT"/"$ARCHIVE")"
#log "Add \"$_REALPATH\" to catalog \"$CATALOG\""
dar_manager --base "$MOUNT_POINT/$CATALOG" -ai -Q --add "$_REALPATH"
RESULT=$?
case $RESULT in
0)
log "\"$_REALPATH\" was added to catalog \"$CATALOG\""
;;
5)
log_warn "Some error(s) were found while adding \"${ARCHIVE}\" to it's catalog"
;;
*)
log_error "something went wrong populating \"$MOUNT_POINT/$CATALOG\", dar_manager error: \"$RESULT\""
exit $RESULT
;;
esac
catalogOpsResult "$RESULT" # dar-util.sh
done < <(find "${MOUNT_POINT}" -type f -name "$SEARCHCRIT" -print|grep -E "${BACKUP_DEF}_FULL_.*|${BACKUP_DEF}_DIFF_.*|${BACKUP_DEF}_INC_.*"| grep -E "^.*?[0-9]{4}-[0-9]{2}-[0-9]{2}" -o| sort -u| sort -t "_" -k 3,3)
fi
fi
Expand Down Expand Up @@ -354,15 +330,15 @@ if [[ $REMOVE_SPECIFIC_ARCHIVE != "" ]]; then
exit 1
fi
CATALOG="${_DEF_}""${CATALOG_SUFFIX}"
log "INFO remove \"$MOUNT_POINT/$REMOVE_SPECIFIC_ARCHIVE\" from catalog \"$CATALOG\""
log "Remove archive \"$MOUNT_POINT/$REMOVE_SPECIFIC_ARCHIVE\" from catalog \"$CATALOG\""
_REALPATH="$(realpath "$MOUNT_POINT"/"$REMOVE_SPECIFIC_ARCHIVE")"
while IFS=$'\n' read -r "line"
do
ARCHIVE_LINE=$(echo "$line"|grep "$REMOVE_SPECIFIC_ARCHIVE")
GREP_RESULT=$?
if [[ $GREP_RESULT == "0" ]]; then
CATALOG_NO=$(echo "$ARCHIVE_LINE"|grep -E "^\s+[0-9]+" -o|grep -E [0-9]+ -o)
log "found archive \"$REMOVE_SPECIFIC_ARCHIVE\" with CATALOG_NO: $CATALOG_NO"
log "Found archive \"$REMOVE_SPECIFIC_ARCHIVE\" with CATALOG_NO: $CATALOG_NO"
dar_manager --base "$MOUNT_POINT"/"$CATALOG" --delete $CATALOG_NO
RESULT=$?
if [[ "$RESULT" == "0" ]]; then
Expand Down
Binary file added doc/pics/log-example-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4c61ee6

Please sign in to comment.