JBAS-315 circ anon script supports configurable windows
authorBill Erickson <berickxx@gmail.com>
Wed, 21 Jan 2015 21:36:42 +0000 (16:36 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Allow the anonymizer to process arbitrarily large windows of
circulations based on their xact_finish date.  This makes it faster to
re-process old circs to accommodate changes in user settings which makes
older circs eligible for anonymization.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/utility-scripts/purge_circs/purge_circulations.sh

index 13e1306..3ed8186 100644 (file)
@@ -5,6 +5,7 @@ USAGE="thisscript.sh --start <xact_finish start date like YYYY-MM-DD> --duration
 DATE_START=""     #action.circulation.xact_finish date to start with; passed as a parameter to psql
 MAX_DURATION_MINUTES=""   #Do not call psql again after this many minutes
 MAX_DATE="" # if set, do not process circs whose action.circulation.xact_finish exceeds this date
+INCREMENT="1 day"
 while [ $# -gt 0 ] ; do
        case $1 in
                --start) DATE_START="$2"
@@ -16,6 +17,9 @@ while [ $# -gt 0 ] ; do
                --end) MAX_DATE="$2"
                        shift
                        ;;
+               --increment) INCREMENT="$2"
+                       shift
+                       ;;
                *) shift
                        ;;
        esac
@@ -46,7 +50,7 @@ echo "This script will stop after $(date --date=@$EPOCH_STOP)."
 EPOCH_NOW=$EPOCH_START
 
 function day_increment {
-       DAY_TO_INCREMENT=$(date --date="$DAY_TO_INCREMENT + 1 day" '+%Y-%m-%d')
+       DAY_TO_INCREMENT=$(date --date="$DAY_TO_INCREMENT + $INCREMENT" '+%Y-%m-%d')
 };
 
 while [[ $EPOCH_NOW -lt $EPOCH_STOP ]] ; do
@@ -54,9 +58,11 @@ while [[ $EPOCH_NOW -lt $EPOCH_STOP ]] ; do
        DAY_TO_INCREMENT=$DATE_START
        day_increment
        DATE_END=$DAY_TO_INCREMENT
-       if [ -n "$MAX_DATE" -a $DATE_START \> $MAX_DATE ]; then
-               echo "Reached max date of $MAX_DATE; exiting"
-               break;
+       if [ -n "$MAX_DATE" -a $DATE_END \> $MAX_DATE ]; then
+               echo "Reached max date of $MAX_DATE; truncating END_DATE"
+               END_DATE=$MAX_DATE
+               # tell the script to stop after this pass
+               EPOCH_STOP=$(date '+%s')
        fi;
        echo "Beginning $DATE_START -- $DATE_END ..."
        psql -U evergreen --file=purge_circulations.psql --quiet --variable=ts_start="'$DATE_START'" --variable=ts_end="'$DATE_END'"
@@ -65,3 +71,4 @@ while [[ $EPOCH_NOW -lt $EPOCH_STOP ]] ; do
        DATE_START=$DAY_TO_INCREMENT
        EPOCH_NOW=$(date '+%s')
 done
+