Files
samba/recycle-cleanup.sh
Struchkov Mark 0363db559d
Some checks failed
continuous-integration/drone/push Build is failing
recycle-cleanup.sh
2026-01-08 01:51:11 +03:00

40 lines
1.3 KiB
Bash

#!/bin/sh
#===============================================================================
# FILE: recycle-cleanup.sh
#
# USAGE: ./recycle-cleanup.sh
#
# DESCRIPTION: Cleanup old files from Samba recycle bins
#
# OPTIONS: ---
# NOTES: Runs via cron when RECYCLE_AGE is set
# AUTHOR: Struchkov Mark (mark@struchkov.dev)
# CREATED: 2025-01-08
#===============================================================================
set -e
SMB_CONF="/etc/samba/smb.conf"
DAYS="${RECYCLE_AGE:-30}"
# Get recycle repository name from config (default: .deleted)
RECYCLE_DIR=$(awk -F' = ' '/recycle:repository/ {print $2}' "$SMB_CONF" | tr -d ' ')
RECYCLE_DIR="${RECYCLE_DIR:-.deleted}"
# Get all share paths from smb.conf
for share_path in $(awk -F' = ' '/^[[:space:]]*path = / {print $2}' "$SMB_CONF"); do
recycle_path="$share_path/$RECYCLE_DIR"
if [ -d "$recycle_path" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') Cleaning $recycle_path (files older than $DAYS days)"
# Delete old files
find "$recycle_path" -type f -mtime +"$DAYS" -delete 2>/dev/null || true
# Delete empty directories
find "$recycle_path" -type d -empty -delete 2>/dev/null || true
fi
done
echo "$(date '+%Y-%m-%d %H:%M:%S') Recycle cleanup completed"