LittleDemon WebShell


Linux hosting5.siteguarding.com 3.10.0-962.3.2.lve1.5.88.el7.x86_64 #1 SMP Fri Sep 26 14:06:42 UTC 2025 x86_64
Path : /usr/local/bin/
File Upload :
Command :
Current File : //usr/local/bin/dxm.rotate_common

#!/bin/bash

#nksupport.com, Pavel Piatruk, 2009-07

export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
#lets assume LOG its default value unless it has been received as 1st command line option  
LOG=${1:-/var/log/dxm/rotate.$LOGNAME.log};

export HOME=$(awk -F:  /^$LOGNAME:/'{print $6}' /etc/passwd )
DESTDIR=~/backups

#define full backups with their increments
SLOTSINCR="`date -d-1week +%Y%m%d` `date +%Y%m%d`
`date -d-2week +%Y%m%d` `date -d-1week +%Y%m%d`"


#define full backups without their increments
SLOTS="`date -d-3week +%Y%m%d` `date -d-2week +%Y%m%d`
`date -d-4week +%Y%m%d` `date -d-3week +%Y%m%d`
`date -d-2month +%Y%m%d` `date -d-4week +%Y%m%d`
`date -d-3month +%Y%m%d` `date -d-2month +%Y%m%d`"


cd $DESTDIR 2>>$LOG  || exit


echo | tee -a $LOG
echo| tee -a $LOG
echo "=== @@@@@ `date` START rotate script in `pwd`" | tee -a $LOG
echo | tee -a $LOG
echo -e "We have SLOTS for just full backups: \n $SLOTS" | tee -a $LOG
echo -e "We have SLOTSINCR for full & incr backups:\n $SLOTSINCR" | tee -a $LOG


echo "=== start chmod'ing files" | tee -a $LOG

find . -mindepth 1 -maxdepth 1 -name '*tgz' -exec chmod -v 440 {} 2>&1 \;    | tee -a $LOG
find . -mindepth 1 -maxdepth 1 -name '*lst' -exec chmod -v 440 {} 2>&1 \;    | tee -a $LOG

echo "=== end chmod'ing files"  | tee -a $LOG


echo "=== we have the following files here: "  | tee -a $LOG
ls -lah  | tee -a $LOG

(mkdir save -pv 2>&1  || exit ) | tee -a $LOG

echo "=== firstly lets save the latest Full backup and its increments"  | tee -a $LOG
find ./ -name "????????.00.tgz"|sort -g|tail -n1 | cut -d/ -f2| awk -F.  '{print "echo these files are part of the latest backup, saving; mv -v "$1".??.tgz* save/"}' | bash  2>&1 | tee -a $LOG

echo "=== start processing SLOTS"  | tee -a $LOG
echo -e "$SLOTS"     | sed 's@^\(.*\) \(.*\)$@ find ./ -name "????????.00.tgz" |cut -d/ -f2 | awk -F. '\''{if (($1>="\1") \&\&  ($1<="\2")) print "echo this file satisfies SLOT \1..\2, saving; mv -v "$1".00.tgz* save/"}'\'' | sort|tail -n 1@'  | sh|sh 2>&1 | tee -a $LOG
echo "=== end processing"  | tee -a $LOG

echo "=== start processing SLOTSINCR"  | tee -a $LOG
echo -e "$SLOTSINCR" | sed 's@^\(.*\) \(.*\)$@ find ./ -name "????????.00.tgz" |cut -d/ -f2 | awk -F. '\''{if (($1>"\1")    \&\& ($1<="\2")) print "echo this file satisfies SLOT \1..\2, saving; mv -v "$1".??.tgz* save/"}'\'' | sort|tail -n 1@'  | sh|sh 2>&1 | tee -a $LOG
echo "=== end processing"  | tee -a $LOG

echo "=== remove remained files from ./ "  | tee -a $LOG
find ./ -maxdepth 1 -mindepth 1 -type f -name '????????.*' -exec rm -fv {} 2>&1 \; 2>&1  | tee -a $LOG
echo "=== move saved files from ./save/ to ./ back "  | tee -a $LOG
find ./save -type f -exec mv -v {} 2>&1 ./ \; 2>&1  | tee -a $LOG
rmdir save 2>&1  | tee -a $LOG

echo "=== there  are following files here in ./: "
ls -lah 2>&1  | tee -a $LOG

echo | tee -a $LOG
echo | tee -a $LOG
echo "=== @@@@@ `date` STOP rotate script in `pwd`" | tee -a $LOG


LittleDemon - FACEBOOK
[ KELUAR ]