Operating System - HP-UX
1835156 Members
2590 Online
110077 Solutions
New Discussion

to exclude files from tar

 
ngari
Regular Advisor

to exclude files from tar

I tried to tar a directory but want to exclude one of the subdiretories...

I tried the command to tar the tmp directory but not /tmp/ex:

tar -cvfX a.tar /tmp/ex /tmp

it doesn't work...

thanks for your solution!!!
3 REPLIES 3
Deoncia Grayson_1
Honored Contributor

Re: to exclude files from tar

a couple of links to read that will help you obtain your desired results:

http://forums1.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=964739

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=993153
If no one ever took risks, Michelangelo would have painted the Sistine floor. -Neil Simon
Geoff Wild
Honored Contributor

Re: to exclude files from tar

Here's how I do it on my linux box:

#!/bin/bash
# Script to backup Directories
#
LOGFILE=/tmp/dumphome.log
GZFILE=`date |awk '{print ($1)}'`.tar.gz
TARFILE=`date |awk '{print ($1)}'`.tar

echo "Backup of files on Ix at " `date` >$LOGFILE 2>&1

# remove the old gzip file
if [ -f /home/backups/$GZFILE ]; then
rm -f /home/backups/$GZFILE >>$LOGFILE 2>&1
else
echo "no old $GZFILE found..." >>$LOGFILE 2>&1
fi

# backup the files
tar -cf /home/backups/$TARFILE `cat /root/backupfiles` >>$LOGFILE 2>&1

# gzip the tar file
gzip /home/backups/$TARFILE >>$LOGFILE 2>&1
chown backup /home/backups/$GZFILE
echo "/home/dumphome is complete " `date` >>$LOGFILE 2>&1

mail -s "Ix: Home Backup Complete" gjwild <$LOGFILE




# cat /root/backupfiles
/bin
/boot
/dev
/etc
/home/httpd
/initrd
/lib
/misc
/mnt
/opt
/proc
/root
/sbin
/scripts
/tmp
/usr
/var

Notice, that in /home, I only backup /home/httpd

Basically, instead of excluding, I implicitly include.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: to exclude files from tar

Here's how I do it on my linux box:

#!/bin/bash
# Script to backup Directories
#
LOGFILE=/tmp/dumphome.log
GZFILE=`date |awk '{print ($1)}'`.tar.gz
TARFILE=`date |awk '{print ($1)}'`.tar

echo "Backup of files on Ix at " `date` >$LOGFILE 2>&1

# remove the old gzip file
if [ -f /home/backups/$GZFILE ]; then
rm -f /home/backups/$GZFILE >>$LOGFILE 2>&1
else
echo "no old $GZFILE found..." >>$LOGFILE 2>&1
fi

# backup the files
tar -cf /home/backups/$TARFILE `cat /root/backupfiles` >>$LOGFILE 2>&1

# gzip the tar file
gzip /home/backups/$TARFILE >>$LOGFILE 2>&1
chown backup /home/backups/$GZFILE
echo "/home/dumphome is complete " `date` >>$LOGFILE 2>&1

mail -s "Ix: Home Backup Complete" gjwild <$LOGFILE




# cat /root/backupfiles
/bin
/boot
/dev
/etc
/home/httpd
/initrd
/lib
/misc
/mnt
/opt
/proc
/root
/sbin
/scripts
/tmp
/usr
/var

Notice, that in /home, I only backup /home/httpd

Basically, instead of excluding, I implicitly include.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.