diff options
| author | Steph Enders <steph@senders.io> | 2025-12-26 21:05:24 -0500 |
|---|---|---|
| committer | Steph Enders <steph@senders.io> | 2025-12-30 11:51:37 -0500 |
| commit | 725180192e51be7c4408cd5de45fb0688f792216 (patch) | |
| tree | 8fe2ff1162bbaa4b57ac05a8f6a2fab06ead540a /ssync-reapr | |
| parent | 519e2e01392e6db171937c4fc707345634fb5236 (diff) | |
Create ssync-reapr to clean up ssync run files
ssync-reapr will delete the run files pushed to the ssync output
dir (default ~/.local/share/ssync/runs/) which can accumulate over
time. The default is to only delete files older than a day.
We run the reap as the first step of every ssync - to ensure it clears
out the necessary files
Diffstat (limited to 'ssync-reapr')
| -rwxr-xr-x | ssync-reapr | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/ssync-reapr b/ssync-reapr new file mode 100755 index 0000000..18fa0c5 --- /dev/null +++ b/ssync-reapr @@ -0,0 +1,71 @@ +#!/usr/bin/env sh + +USAGE="ssync-reapr [options] [dirs...] + OPTIONS + -a AGE (in seconds) + limit the reaping of files no older than this seconds old. + Default is 86400 (1 day) + -n dry run + -v verbose logging (use -vv to log reaped files) + -h print this message" + +# HELPER FUNCTIONS +verbose_log() { + if [ ! -z "$VERBOSE_FLAG" ]; then + echo "$@" + fi +} + +# OPTIONS + +AGE_FLAG= +AGE_OPT= +DRY_RUN_FLAG= +VERBOSE_FLAG= +while getopts "hnva:" opt; do + case "${opt}" in + h) echo "$USAGE" + exit 1 + ;; + a) AGE_FLAG=1 + AGE_ARG="${OPTARG}" + ;; + n) DRY_RUN_FLAG=1 + ;; + v) VERBOSE_FLAG=$(($VERBOSE_FLAG +1)) + ;; + esac +done + +shift $(($OPTIND -1)) + +DIRS="$@" + +# Reaper + +rm_flag= +if [ -z "$DRY_RUN_FLAG" ]; then + rm_flag="-delete" + if [ $VERBOSE_FLAG -gt 1 ]; then + rm_flag="$rm_flag -print" + fi +else + verbose_log "Dry run!" + rm_flag="-print" +fi + +target_date= +if [ -z "$AGE_FLAG" ]; then + target_date=$(date -d "86400 seconds ago" -Is) +else + target_date=$(date -d "${AGE_ARG} seconds ago" -Is) +fi +window_flag="-not -newermt ${target_date}" + +verbose_log "Reaping files older than $target_date: $window_flag" + +for dir in $DIRS; do + target=$(realpath $dir) + verbose_log "Clearing files in $target" + find $target -type f $window_flag $rm_flag +done |