I am suggesting the script which you have done on the computer of yours. it is named as backup.sh and I have mentioned the same as follow.
Code:
#!/bin/sh
# DELETE archive older than -mtime +'days'
find . -name 'BACKUP*.tgz' -mtime +20 -delete
find . -name 'stopwatch*' -mtime +2 -delete
start1=$(date +"%T h ( %s )")
start=$(date +%s)
# on SUNDAY make FULL backup
if [ $(date +"%a") = "Sun" ]; then
{
SNAPSHOTFILE="./usr-full"; # needed by TAR (GNU-TAR to be precise) which is used to compare for incremental backups
ARCHIVENAME=BACKUP-full-$(date +"%F-%a-%H-%M-%Sh").tgz; # self explaining
rm -f "./usr-full";
}
else
{
ARCHIVENAME=BACKUP-$(date +"%F-%a-%H-%M-%Sh").tgz;
# a name of a backup file: BACKUP-2009-12-15-Fri-01-15-01h.tgz
SNAPSHOTFILE="./usr-1";
cp "./usr-full" "./usr-1";
}
fi
echo $ARCHIVENAME >archivename.txt # need the name to FTP transfer so store it in file archivename.txt which doesn't change (used later in lftpscript.sh ) !
# creating text to send in email
echo "-----------------------" >stopwatch-$archivename.txt
echo "Backup of $ARCHIVENAME" >>stopwatch-$archivename.txt
echo "-----------------------" >>stopwatch-$archivename.txt
echo " " >>stopwatch-$archivename.txt # echo " " makes new line /CR or LF whatever it does
# I do not need this precise time { time tar -T including.txt -X excluding.txt -pczvRf $ARCHIVENAME; } 2>> stopwatch-$ARCHIVENAME.txt >/dev/null
{ tar -T including.txt -X excluding.txt -pczvR --listed-incremental=$SNAPSHOTFILE -f $ARCHIVENAME; } 2>> stopwatch-$ARCHIVENAME.txt >/dev/null
stopped1=$(date +"%T h ( %s )")
stopped=$(date +%s)
ftpstarted=$stopped
thetime=$(($stopped-$start)) # doing some math in shell that's why $()
echo " " >>stopwatch-$ARCHIVENAME.txt
echo -n "File Size (Byte-s) : " >>stopwatch-$ARCHIVENAME.txt
ls -al "$ARCHIVENAME" | cut -f 5 -d ' ' >>stopwatch-$ARCHIVENAME.txt
# this part | cut -f 5 -d ' ' is sometimes maybe 6 instead of 5, experiment which gives you only the SIZE of the file
echo " " >>stopwatch-$ARCHIVENAME.txt
echo "Started: " $start1 >>stopwatch-$ARCHIVENAME.txt
echo "Stopped: " $stopped1 >>stopwatch-$ARCHIVENAME.txt
echo "Time needed: " $(date -d "1970-01-01 $thetime sec" +"%H:%M:%S") / $thetime "secs" >>stopwatch-$ARCHIVENAME.txt
# outputs: Time needed: 00:03:14 / 194 secs
echo "-----------------------" >>stopwatch-$ARCHIVENAME.txt
echo " " >>stopwatch-$ARCHIVENAME.txt
echo "FTP start:" >>stopwatch-$ARCHIVENAME.txt
# again I dont need exact time procedure { time ./lftpscript.sh; } 2>> stopwatch-$ARCHIVENAME.txt
{ ./lftpscript.sh; } 2>> stopwatch-$ARCHIVENAME.txt
ftpstop1=$(date +"%T h ( %s )")
ftpstopped=$(date +%s)
ftptime=$(($ftpstopped-$ftpstarted))
echo " " >>stopwatch-$ARCHIVENAME.txt
echo "Start of FTP: " $stopped1 >>stopwatch-$ARCHIVENAME.txt
echo "End of FTP: " $ftpstop1 >>stopwatch-$ARCHIVENAME.txt
echo "Time of FTP transfer: " $(date -d "1970-01-01 $ftptime sec" +"%H:%M:%S") / $ftptime "secs" >>stopwatch-$ARCHIVENAME.txt
mail -s "Backup of $ARCHIVENAME" "email address of recipient" <stopwatch-$ARCHIVENAME.txt
#finally email report :-)
So use the above mentioned and let me know if there is bug in the script which I have mentioned above.
Bookmarks