1

I have a file named backup.sh. I just want to take backup only html directory and its all sub directories and files. But I'm getting all the parent directory of html directories as well like var, www which is not required for me.

I'm pasting the code below:

#!/bin/bash
#Purpose = Backup of Important Data
DATE=$(date +"%d-%b-%Y")
SRCDIR="/var/www/html"
DESDIR="/media/HDD-01/html"
FILENAME=html-$DATE.tar.gz

# Making backup with compress 
tar -cpzf $DESDIR/$FILENAME $SRCDIR

I got this code from below link:

http://broexperts.com/2012/06/how-to-backup-files-and-directories-in-linux-using-tar-cron-jobs/

Can anyone suggest me how can I solved my problem?

Thanks in advance.

Rezuan
  • 243

1 Answers1

5

Go for alternate: .. :)

#!/bin/bash
#Purpose = Backup of Important Data
DATE=$(date +"%d-%b-%Y")
cd /var/www/
tar -zcvf HTML-$DATE.tgz html
mv *.tgz /media/HDD-01/html
Rezuan
  • 243