From 725180192e51be7c4408cd5de45fb0688f792216 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Fri, 26 Dec 2025 21:05:24 -0500 Subject: 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 --- ssync-reapr | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 ssync-reapr (limited to 'ssync-reapr') 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 -- cgit v1.2.3-54-g00ecf