soulshepard
Verified User
- Joined
- Feb 7, 2008
- Messages
- 128
dont know if any has allready has a script like this or a functionality is coming soon, but to not run out of diskspace i have made this addition as a cron script to clean up the "xx-xx-xx" type system backups that da makes
in addition i use the admin backup/transfer for all the user/reseller data backup this overwrites nicely
the system backup if you would ever need to rebuild fast it would be handy to have it thats why i also use the systembackup.
if any one has an idea of how i could improve suggestions are allways welcome. but this is done to my abbilities and view and it works for my servers
the script parses a directory, finds the folderd xx-xx-xx, replaces the "-" and substracts the days, in a case loop i walk all those results and removes all but the last 2 days, another way to shorten this is i would only need the previous day then it would be a bit simpeler but for me this is better.
would be nice to see a functionality like this in DA and even better if we would have a pre and post script function so you can customise your actiosn before backups and after backup (pre:mount stuff set rights, start stop stuff and post:dismount copy start stop other stuff)
run this script in your crontab
it uses vars for the binaries that are resolved with which, would be wice to set the which path first and all other would resolve. i dod not made a check if those executables exists, for now this would be bloating a simple functionality but is not unthinkable.
to enable the script please set the ENABLESCRIPT to 1 and TESTMODE to 0 and verify the WHICH path
Soul.
in addition i use the admin backup/transfer for all the user/reseller data backup this overwrites nicely
the system backup if you would ever need to rebuild fast it would be handy to have it thats why i also use the systembackup.
if any one has an idea of how i could improve suggestions are allways welcome. but this is done to my abbilities and view and it works for my servers
the script parses a directory, finds the folderd xx-xx-xx, replaces the "-" and substracts the days, in a case loop i walk all those results and removes all but the last 2 days, another way to shorten this is i would only need the previous day then it would be a bit simpeler but for me this is better.
would be nice to see a functionality like this in DA and even better if we would have a pre and post script function so you can customise your actiosn before backups and after backup (pre:mount stuff set rights, start stop stuff and post:dismount copy start stop other stuff)
run this script in your crontab
it uses vars for the binaries that are resolved with which, would be wice to set the which path first and all other would resolve. i dod not made a check if those executables exists, for now this would be bloating a simple functionality but is not unthinkable.
to enable the script please set the ENABLESCRIPT to 1 and TESTMODE to 0 and verify the WHICH path
Soul.
HTML:
#!/bin/sh
#
### Clean DA system backup script ###
###
### version 1.2
###
### jan [AT] makeitwork [DOT] nu
###
## Config
##
## set these values to enable the script. (0=off 1=on)
#
ENABLESCRIPT=0
TESTMODE=1
## Supply the which binary path, this will resolve all other binaries for the script.
#
WHICH="/usr/bin/which"
## Directadmin backup Path
#
BACKUPPATH=/backup/directadmin-system
## Date format
# direactadmin uses month-day-year (with creating my backup folders) with sed we remove the - and match the date format in the caseselect
#
DATEFORMAT="+%m%d%y"
## Binary Setup
#
DATE="$($WHICH date)"
GREP="$($WHICH grep)"
CUT="$($WHICH cut)"
RM="$($WHICH rm)"
SED="$($WHICH sed)"
LS="$($WHICH ls | $GREP -v "alias")"
ECHO="$($WHICH echo)"
### Start Executing
##
# make sure we did edit the script after download.
#
if [ ! "x$ENABLESCRIPT" = "x1" ];
then
$ECHO edit the script to anable it
exit 1
fi
## Collect backup entries in the supplied folder.
#
LSOUTPUT="$($LS $BACKUPPATH | $SED 's/-//g' | $GREP -i $($DATE +"%y"))"
## Main Loop
#
for results in $LSOUTPUT
do
## Make sure $results is not empty
#
if [ ! "x$results" = "x" ];
then
## recreating filename from dateformat
#
REMOVETARGET=`$ECHO ${results:0:2}-${results:2:2}-${results:4:2}`
#
## walk each $results and remove it if it does not hit, the case else (*) will remove the entry.
#
case $results in
## skip today
#
$($DATE --date='-0 day' "$DATEFORMAT"))
$ECHO skipping : $BACKUPPATH/$REMOVETARGET
;;
## skip yesterday
#
$($DATE --date='-1 day' "$DATEFORMAT"))
$ECHO skipping : $BACKUPPATH/$REMOVETARGET
;;
## remove all other
#
* )
$ECHO REMOVING : $BACKUPPATH/$REMOVETARGET
if [ "x$TESTMODE" = "x1" ];
then
$ECHO "*** Testmode will not delete, edit script to disable ***"
else
if [ ! "x$REMOVETARGET" = "x" ] ;
then
$ECHO " : $RM -rf $BACKUPPATH/$REMOVETARGET"
$RM -rf $BACKUPPATH/$REMOVETARGET
fi
fi
;;
esac
REMOVETARGET=
else
$ECHO "error empty results $results"
fi
done
Last edited: