Cron remove failed backup folders

ssgill

Verified User
Joined
May 9, 2012
Messages
164
Hello, is there cron or directadmin settings to remove backup folder after certain time if backup does not finnish or fails.

This morning home directory went to 100% because of failed backups. What i am looking for is if backup files are on server after certain period delete them irrespective if backup was success or fail.

Had couple of folders in home/tmp from past couple of weeks that filled up the hard drive.

Thanks
 
it will be good idea, but you can still change backup-temporary dir to another disk/ramdrive also enable pigz to speed up backups and make lower failures.
 
we doing it with tmpwatch and a hourly cron (now its backupwatch for us)
/usr/local/sbin/tmpwatch -maf 30d /backup --exclude /backup/[some-folder-to-exclude-from-deleting] >/dev/null 2>&1
 
we doing it with tmpwatch and a hourly cron (now its backupwatch for us)
/usr/local/sbin/tmpwatch -maf 30d /backup --exclude /backup/[some-folder-to-exclude-from-deleting] >/dev/null 2>&1

Thanks, this might work.

I just installed tmpreaper ( tmpwatch for Debian ), just want to clarify few points.

/etc/tmpreaper.conf

Comes with preset daily cron and will work on /tmp folder. I am thinking of modifying config to work on /home/tmp instead of /tmp. Cron suits my needs i just need to change couple of lines in config file


# TMPREAPER_TIME=7d --> no change needed as 7 days is what i am looking at, if needed can comment out and change the range

TMPREAPER_PROTECT_EXTRA='' --> no change every file in this location needs to go
TMPREAPER_DIRS='/tmp/.' --> change to '/home/tmp/.'
TMPREAPER_DELAY='256' --> not sure leave at default
TMPREAPER_ADDITIONALOPTIONS='' --> leave it blank, every file not listed in TMPREAPER_PROTECT_EXTRA will be deleted

This way i don't need to setup anything special and get the job done.
Any input will be welcomed, thanks for your time.
 
Hello, is there cron or directadmin settings to remove backup folder after certain time if backup does not finnish or fails.

This morning home directory went to 100% because of failed backups. What i am looking for is if backup files are on server after certain period delete them irrespective if backup was success or fail.

Had couple of folders in home/tmp from past couple of weeks that filled up the hard drive.

Thanks
No DA doesn’t have this feature. It’s been requested on the feedback site. You have to create a script to clean old backups locally.
 
Thanks for the reply. I did installed "tmpreaper" as @johannes posted ( tmpwatch ), just want to confirm if anyone else have used it on debian. For now it will not run because i have not removed show warning flag, this should stop the cron with error message.

Instead of adding my own cron would like to edit daily cron that's installed by default.

/etc/tmpreaper.conf

# tmpreaper.conf
# - local configuration for tmpreaper's daily run
#
# This is only used if /etc/cron.daily/tmpreaper was also updated,
# i.e. there's a line ". /etc/tmpreaper.conf" in that file.
# The shell code that used to be here (pre version 1.6.7) is now
# in the cron.daily script.

# Remove the next line if you understand the possible security implications of
# having tmpreaper run automatically;
# see /usr/share/doc/tmpreaper/README.security.gz

SHOWWARNING=true

# TMPREAPER_TIME
# is the max. age of files before they're removed.
# default:
# the TMPTIME value in /etc/default/rcS if it's there, else
# TMPREAPER_TIME=7d (for 7 days)
# I recommend setting the value in /etc/default/rcS, as
# that is used to clean out /tmp whenever the system is booted.
#
# TMPREAPER_PROTECT_EXTRA
# are extra patterns that you may want to protect.
# Example:
# TMPREAPER_PROTECT_EXTRA='/tmp/isdnctrl* /tmp/important*'
#
# TMPREAPER_DIRS
# are the directories to clean up.
# *never* supply / here! That will wipe most of your system!
# Example:
# TMPREAPER_DIRS='/tmp/. /var/tmp/.'
#
# TMPREAPER_DELAY
# defines the maximum (randomized) delay before starting processing.
# See the manpage entry for --delay. Default is 256.
# Example:
# TMPREAPER_DELAY='256'
#
# TMPREAPER_ADDITIONALOPTIONS
# extra options that are passed to tmpreaper, e.g. --all

# uncomment and change the next line to overrule the /etc/default/rcS value
# TMPREAPER_TIME=7d

TMPREAPER_PROTECT_EXTRA=''
TMPREAPER_DIRS='/tmp/.'
TMPREAPER_DELAY='256'
TMPREAPER_ADDITIONALOPTIONS=''



/etc/cron.daily/tmpreaper

#!/bin/sh
PATH=/usr/sbin:/usr/bin:/sbin:/bin

# in case of `dpkg -r' leaving conffile.
if ! [ -x /usr/sbin/tmpreaper ]; then
exit 0
fi

# Remove `/tmp/...' files not accessed in X time (configured in
# /etc/tmpreaper.conf, default 7 days), protecting the .X, .ICE, .iroha and
# .ki2 files; but removing symlinks. For directories not the access time, but
# the modification time is used (--mtime-dir), as reading a directory to check
# the contents will update the access time!
#
# In the default, /tmp/. is used, not the plain /tmp you might expect, as this
# accomodates the situation where /tmp is a symlink to some other place.
#
# Note that the sockets are safe even without the `--protect', unless `--all'
# is given, and the `.X*-lock' files would be safe also, as long as they have
# no write permissions, so this particular protect is mainly illustrative, and
# redundant. For best results, don't try to get fancy with the moustache
# expansions. KISS. Always --test your protect patterns.
#
# Immutable files (such as ext3fs' .journal) are not (cannot be) removed;
# when such a file is encountered when trying to remove it, no error is given
# unless you use the --verbose option in which case a message is given.
#
# In case you're wondering: .iroha is for cannaserver and .ki2 is for kinput2
# (japanese software, lock files).
# journal.dat is for (older) ext3 filesystems
# quota.user, quota.group is for (duh) quotas.

# Set config defaults
SHOWWARNING=''

# get the TMPREAPER_TIME value from /etc/default/rcS

if grep '^TMPTIME=' /etc/default/rcS >/dev/null 2>&1; then
eval $(grep '^TMPTIME=' /etc/default/rcS)
if [ -n "$TMPTIME" ]; then
# Don't clean files if TMPTIME is negative or 'infinite'
# to mimic the way /lib/init/bootclean.sh works.
case "$TMPTIME" in
-*|infinite|infinity)
# don't use this as default
;;
*)
if [ "$TMPTIME" -gt 0 ]; then
TMPREAPER_TIME=${TMPTIME}d
else
TMPREAPER_TIME=7d
fi
;;
esac
fi
fi

# ! Important ! The "set -f" below prevents the shell from expanding
# file paths, which is vital for the configuration below to work.

set -f

# preserve environment setting of TMPREAPER_DELAY to allow manual override when
# running the cron.daily script by hand:
if [ -n "$TMPREAPER_DELAY" ]; then
# check for digits only
case "$TMPREAPER_DELAY" in
[0-9]*) TMPREAPER_DELAY_SAVED="$TMPREAPER_DELAY";;
*) ;;
esac
fi

if [ -s /etc/tmpreaper.conf ]; then
. /etc/tmpreaper.conf
fi

# Now restore the saved value of TMPREAPER_DELAY (if any):
if [ -n "$TMPREAPER_DELAY_SAVED" ]; then
TMPREAPER_DELAY="$TMPREAPER_DELAY_SAVED"
else
# set default in case it's not given in tmpreaper.conf:
TMPREAPER_DELAY=${TMPREAPER_DELAY:-256}
fi

if [ "$SHOWWARNING" = true ]; then
echo "Please read /usr/share/doc/tmpreaper/README.security.gz first;"
echo "edit /etc/tmpreaper.conf to remove this message (look for SHOWWARNING)."
exit 0
fi

# Verify that these variables are set, and if not, set them to default values
# This will work even if the required lines are not specified in the included
# file above, but the file itself does exist.
TMPREAPER_TIME=${TMPREAPER_TIME:-7d}
TMPREAPER_PROTECT_EXTRA=${TMPREAPER_PROTECT_EXTRA:-''}
TMPREAPER_DIRS=${TMPREAPER_DIRS:-'/tmp/.'}

nice -n10 tmpreaper --delay=$TMPREAPER_DELAY --mtime-dir --symlinks $TMPREAPER_TIME \
$TMPREAPER_ADDITIONALOPTIONS \
--ctime \
--protect '/tmp/.X*-{lock,unix,unix/*}' \
--protect '/tmp/.ICE-{unix,unix/*}' \
--protect '/tmp/.iroha_{unix,unix/*}' \
--protect '/tmp/.ki2-{unix,unix/*}' \
--protect '/tmp/lost+found' \
--protect '/tmp/journal.dat' \
--protect '/tmp/quota.{user,group}' \
--protect '/tmp/sess_*/*' \
--protect '/tmp/systemd-private*/*' \
`for i in $TMPREAPER_PROTECT_EXTRA; do echo --protect "$i"; done` \
$TMPREAPER_DIRS

Added content of the config and cron files if it helps.

Thanks
 
Back
Top