Skip to content

Instantly share code, notes, and snippets.

@kantjer01
Last active July 29, 2023 17:28
Show Gist options
  • Save kantjer01/304638e59ee3026b96365026ebd42d72 to your computer and use it in GitHub Desktop.
Save kantjer01/304638e59ee3026b96365026ebd42d72 to your computer and use it in GitHub Desktop.
upgraderr-freespace.sh
#!/bin/bash
# This script deletes the oldest movies and series torrents on qbit instances on the localhost when the free disk space drops below a set value.
# load variables
set -o allexport
source /volume1/scripts/upgraderr/upgraderr.env
set +o allexport
log="$log_dir/freespace.$(date +"%Y-%m-%d_%H.%M").log"
freespace_min=1250 # minimal free diskspace in GB
completed_m=75 # minimal days to keep movies torrents in days
completed_s=50 # minimal days to keep series torrents in days
# If freespace is low, delete max 100 movies torrents
echo "Delete max 100 movies torrents older than $completed_m days" | tee $log
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" <<CURL_DATA | tee -a $log
{"host":"${host_movies_local}",
"user":"${user_local}",
"password":"${password_local}",
"action":"delete",
"query":"DisableCrossseed() && State(State) == 'stalledUP' && Tags not contains 'keep' && Tags not contains 'BeyondHD' && SpaceFree('/lts_dir') < $freespace_min*1024*1024*1024 && ResultLimit(100) && Now() - CompletionOn > $completed_m*24*60*60",
"sort":"-CompletionOn"}
CURL_DATA
# If freespace is low, delete max 100 series torrents
echo "Delete max 100 series torrents older than $completed_s days" | tee -a $log
curl -X POST -H "Content-Type: application/json" -d @- "$webhook_url" <<CURL_DATA | tee -a $log
{"host":"${host_series_local}",
"user":"${user_local}",
"password":"${password_local}",
"action":"delete",
"query":"DisableCrossseed() && State(State) == 'stalledUP' && Tags not contains 'keep' && Tags not contains 'BeyondHD' && SpaceFree('/lts_dir') < $freespace_min*1024*1024*1024 && ResultLimit(100) && Now() - CompletionOn > $completed_s*24*60*60",
"sort":"-CompletionOn"}
CURL_DATA
# cleanup log files
if ls -t $log_dir/freespace.*.log &>/dev/null; then
ls -t $log_dir/freespace.*.log | tail -n +4 | xargs rm -f --
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment