Skip to content

Commit

Permalink
cleanup cleanup.sh :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
per2jensen committed Jul 24, 2022
1 parent 77488fc commit c478302
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions bin/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,16 @@ log "Cleanup in: \"$MOUNT_POINT\""
# make sure mounts are in order
mountPrereqs


# date --date="-1 days" -I

# ls /tmp/dar-backup-test/archives/*.dar|grep -o -E "[0-9]{4}-[0-9]{2}-[0-9]{2}"
#

DIFF_AGE_DATE=$(date --date="-${DIFF_AGE} days" -I)
DIFF_AGE_SECS=$(date +%s --date "$DIFF_AGE_DATE")
#echo DIFF_AGE_DATE: $DIFF_AGE_DATE
#echo DIFF_AGE_SECS: $DIFF_AGE_SECS

#clean up DIFFs
while IFS= read -r -d "" file
do
#echo $file
FILE_DATE=$(echo $file|grep -o -E "_DIFF_[0-9]{4}-[0-9]{2}-[0-9]{2}")
FILE_DATE=$(echo $file|grep -o -E "_DIFF_[0-9]{4}-[0-9]{2}-[0-9]{2}") # don't find dates in directory names
FILE_DATE=$(echo $FILE_DATE|grep -o -E "[0-9]{4}-[0-9]{2}-[0-9]{2}")
#echo date: $FILE_DATE
FILE_DATE_SECS=$(date +%s --date "$FILE_DATE")
#echo file date secs: $FILE_DATE_SECS
#echo DIFFS secs: $DIFF_AGE_SECS
if (( DIFF_AGE_SECS >= FILE_DATE_SECS )); then
#echo should be deleted: $file
rm -f "${file}" && log "clean up: \"${file}\""
fi
done < <(find "$MOUNT_POINT" -type f -name "*_DIFF_*.dar*" -print0)
Expand All @@ -84,24 +71,16 @@ done < <(find "$MOUNT_POINT" -type f -name "*_DIFF_*.dar*" -print0)

INC_AGE_DATE=$(date --date="-${INC_AGE} days" -I)
INC_AGE_SECS=$(date +%s --date "$INC_AGE_DATE")
#echo INC_AGE_DATE: $INC_AGE_DATE
#echo INC_AGE_SECS: $INC_AGE_SECS

#clean up INCs
while IFS= read -r -d "" file
do
#echo $file
FILE_DATE=$(echo $file|grep -o -E "_INC_[0-9]{4}-[0-9]{2}-[0-9]{2}")
FILE_DATE=$(echo $file|grep -o -E "_INC_[0-9]{4}-[0-9]{2}-[0-9]{2}") # don't find dates in directory names
FILE_DATE=$(echo $FILE_DATE|grep -o -E "[0-9]{4}-[0-9]{2}-[0-9]{2}")
#echo date: $FILE_DATE
FILE_DATE_SECS=$(date +%s --date "$FILE_DATE")
#echo file date secs: $FILE_DATE_SECS
#echo INC secs: $INC_AGE_SECS
if (( INC_AGE_SECS >= FILE_DATE_SECS )); then
#echo should be deleted: $file
rm -f "${file}" && log "clean up: \"${file}\""
fi
done < <(find "$MOUNT_POINT" -type f -name "*_INC_*.dar*" -print0)

log "$SCRIPTNAME ended normally"

0 comments on commit c478302

Please sign in to comment.