Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

Bash Script To Clean 2+ Days Old Autobackup

mv ~/full_backup/daily/* ~/full_backup/archive/ &>/dev/null
mkdir ~/AutobackupLogs &>/dev/null
ls -ltr ~/full_backup/archive/ | awk '{print $9}' > ~/AutobackupLogs/dirnames

for i in `cat ~/AutobackupLogs/dirnames`; do
        Ptime=$(date +%s -d"$i 00:00:00")
        Ctime=$(date +%s)
        echo $((Ctime-Ptime)) | awk '{print int($i/86400)}' > ~/AutobackupLogs/timecalc

        Cvalue=`cat ~/AutobackupLogs/timecalc`
        if [ $Cvalue -gt 2 ]; then
                echo "Directory: '$i' removed, $Cvalue days old." >> ~/AutobackupLogs/rmjob
                rm -rf ~/full_backup/archive/$i &>/dev/null
        fi
        done

rm -f ~/AutobackupLogs/timecalc
rm -f ~/AutobackupLogs/dirnames
vim ~/AutobackupLogs/rmjob
 
PREVIOUS NEXT
Tagged: #Bash #Script #To #Clean #Days #Old #Autobackup
ADD COMMENT
Topic
Name
2+8 =