==========> Backup Script
#!/bin/bash# Shirish Shukla backup script
# source-> /usr/rnd/*
# target-> /shirishva/backup/abcd-...
#
#------------ Backup string create: abcd-Wed-Oct-27-22:31 format
create=$(echo abcd-`date +%a-%b-%d-%H:%M`)
tar -jcf /shirishva/backup/$create.bz2 /usr/rnd/*
#------------------- delete 3 Hour old backup data del->string
t1=$(date --date='3 hour ago')
t2=$(echo $t1 | sed -e "s/[:]/ /g")
array=( `echo $t2` )
del=$(echo abcd-${array[0]}-${array[1]}-${array[2]}-${array[3]}:${array[4]})
rm -fr /shirishva/backup/$del.bz2
#---------------------------------
crontab to every hour
ReplyDelete0 * * * * * /shirishva/scripts/backup.sh
or cp /shirishva/scripts/backup.sh /etc/cron.hourly/
IF your backup process take more than 1 minute then above deletion process fails so just
ReplyDeletecut paste below line at the top of script below line
# target-> /shirishva/backup/abcd-..
t1=$(date --date='3 hour ago')
t2=$(echo $t1 | sed -e "s/[:]/ /g")
array=( `echo $t2` )
del=$(echo abcd-${array[0]}-${array[1]}-${array[2]}-${array[3]}:${array[4]})
-- so that your del time sets accordingly
otherwise it may set to time after backup process conmplete..
-----Have a fniing moment shirish shukla (mod)
#!/bin/bash
ReplyDelete# Shirish Shukla backup script
# source-> /usr/rnd/*
# target-> /shirishva/backup/abcd-...
#
#------------ Backup string create: abcd-Wed-Oct-27-22:31 format
create=$(echo abcd-`date +%a-%b-%d-%H:%M`)
tar -jcf /shirishva/backup/$create.bz2 /usr/rnd/*
#------------------- delete 3 Hour old backup data del->string
del=$(date --date='3 hour ago'|sed -e 's/[:]/ /g'|awk '{print "abcd-"$1"-"$2"-"$4":"$5}')
rm -fr /shirishva/backup/$del.bz2
#--------------------------------- Shirish Shukla
IN SORT --Updated by: Shirish Shukla
ReplyDeletethanks
ReplyDelete