View Single Post
  #2  
Old 6th July 2012, 13:30
TiTex TiTex is offline
Senior Member
 
Join Date: Aug 2011
Location: Cluj-Napoca,Romania
Posts: 125
Thanks: 0
Thanked 17 Times in 17 Posts
Send a message via Skype™ to TiTex
Default

I'm trying to learn bash scripting , so will this work for you ?

Code:
#!/bin/bash

##Current day in numeric format i.e 31
day=$(date +%d)

##Current month in numeric format i.e 12
month=$(date +%m)

##Current year in 4 digit format i.e 2012
year=$(date +%Y)

##Last month in numeric format
lmonth=$(date -d "last month" +%m)

##Number of days in previous month
lday=`cal $lmonth $year | egrep -v [a-z] | wc -w`

FILENAME=backup-$(date -d "last month" +%Y-%m).txt
touch $FILENAME
touch --date "$year-$lmonth-01" /tmp/start
touch --date "$year-$lmonth-$lday" /tmp/end

mount -t nfs netdisk219:/mnt//vol001/volume02/Archive/Database /backup
find /data/nightly_data_backup -type d -newer /tmp/start -not -newer /tmp/end -print | sort > $FILENAME
tar -czvf /backup/$year"_"$lmonth".tar.gz" --files-from $FILENAME

Last edited by TiTex; 6th July 2012 at 13:35.
Reply With Quote