1846639 Members
1747 Online
110256 Solutions
New Discussion

Re: Selective TAR Backup

 
SOLVED
Go to solution
Greg Stark_1
Frequent Advisor

Selective TAR Backup

I have a directory I want to dump to tape called /opt/sai. There are multiple files and directories in it. I want everything in it backed up except a directory calle .snapshot.

Any way to accomplish this with tar?
8 REPLIES 8
Hoefnix
Honored Contributor

Re: Selective TAR Backup

Hi,

You can use the -X option of tar to exclude files.

At the moment I am using Linux at home, so can't check if this is also in HP-UX.

HTH,

Peter
Tanmay_1
Occasional Advisor
Solution

Re: Selective TAR Backup

Greg,

Do the following.
cd /opt/sai
ls > file_list
vi file_list
(remove the directory you want to remove)
go to the last of first line and press j. And keep on doing it, till all lines are converted in a single line.
Go to the begning of first line and type tar command like, tar cvf /dev/rmt/0m .
Save the file
Run it. #sh ./file_list

Rick Garland
Honored Contributor

Re: Selective TAR Backup

Here is an option

From the directory you want to backup (minus the .snapshot directory)

tar -cvf yourname.tar `ls | grep -v .snapshot`

Notice the backticks, not single quotes.


Jeff_Traigle
Honored Contributor

Re: Selective TAR Backup

No option on HP's tar to do this.

The solutions mentioned already give you relative backup of the directory and will only eliminate .snapshot in that particular directory, not in any subdirectories that might exist.

Not as simple as it looks for a general case situation. Would be easier with fbackup. Any reason you need to use tar (i.e. portability to other UNIX variants or between older and newer revisions of HP-UX)?
--
Jeff Traigle
Jeff_Traigle
Honored Contributor

Re: Selective TAR Backup

And actually, even if the previous solutions would work in your case, don't just do "ls" do "ls -1". With just ls, you get multi-column output by default and you'll end up grepping out .snapshot and whatever happens to show up in the same line of output. "ls -1" will force it single column output and grap will eliminate only what you really want it to.
--
Jeff Traigle
Sundar_7
Honored Contributor

Re: Selective TAR Backup

How about this?

# cd /opt/sai
# tar -cvf SAI.tar $(find . | egrep -v "^./.snapshot|^\.$")
Learn What to do ,How to do and more importantly When to do ?
Jeff_Traigle
Honored Contributor

Re: Selective TAR Backup

I thought of using find similarly, Sundar... the problem is that find lists the directories as well as the files... which means you're making redundant copies of files in your archive and still picking up the .snapshot directories along the way as a result... exactly what Greg's trying to avoid. You can't just exclude directories from find either because, if a directory is empty, it won't be picked up to go into the archive.
--
Jeff Traigle
Greg Stark_1
Frequent Advisor

Re: Selective TAR Backup

Thanks everyone, I created a tar.sh with the ls output on one line and that seemed to work great.