Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Thursday, October 28, 2010

my scripts

==========> 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

#---------------------------------

5 comments:

  1. crontab to every hour
    0 * * * * * /shirishva/scripts/backup.sh

    or cp /shirishva/scripts/backup.sh /etc/cron.hourly/

    ReplyDelete
  2. IF your backup process take more than 1 minute then above deletion process fails so just

    cut 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)

    ReplyDelete
  3. #!/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

    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

    ReplyDelete
  4. IN SORT --Updated by: Shirish Shukla

    ReplyDelete

Write Here .. your comments are always wellcome ..but no spam please !!

Followers

Pls LIKE my Story !!!