#!/bin/tcsh -f setenv BackupRoot "this/should/break/if/not/reset." setenv ArchiveMethod "link-dest" # There must be an easier way to get perl vars into a csh script but this was the first thing I thought of. eval `grep ^.BackupRoot settings/settings.pl | sed -e 's/\$/setenv /' -e 's/=/ /g' -e 's/;//g'` eval `grep ^.ArchiveMethod settings/settings.pl | sed -e 's/\$/setenv /' -e 's/=/ /g' -e 's/;//g'` if ("$ArchiveMethod" == "zfs") then echo "WARNING: This script is designed for link-dest based archives but you are using $ArchiveMethod." echo "The script will continue anyway on the assumption that you might be in the process of migrating from --link-dest to $ArchiveMethod. If that is not the case then you are doing something wrong." echo "However, this script will NOT purge any archives that were made with $ArchiveMethod as they are handled during the backups instead of this extra tool." endif set Verbose="n" if ($1 == "-v") set Verbose="y" if ($1 == "--verbose") set Verbose="y" # Note: the filetest command is part of tcsh but NOT csh :( set FileTest=`filetest -e ${BackupRoot}/*/*.ToBePurged |& cut -c1` if ($FileTest == "1") then foreach DeleteMe (${BackupRoot}/*/*.ToBePurged) if ($Verbose == "y") echo "Purging ${ArchiveMethod}:${DeleteMe}..." if ($ArchiveMethod == "link-dest") rm -rf "$DeleteMe" if ($ArchiveMethod == "btrfs") btrfs subvolume delete "$DeleteMe" end else if ($Verbose == "y") echo "Nothing to purge." endif