PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Nov 23, 2017 12:20 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Mar 20, 2012 11:01 am 
Offline
Forum Commoner

Joined: Thu Mar 10, 2011 2:03 pm
Posts: 32
Hi guys,

I'm the furthest thing you can imagine from a Linux pro, so this may be a bit of a noob question, but I'm running some backups on one of our servers (we don't have an actual SA), and I've recently encountered an annoying problem. When I run the following command to zip the entire current directory (which is normally httpdocs), it seems to include itself in the tarball: (run in httpdocs directory)

Syntax: [ Download ] [ Hide ]
tar -zcvf backup.tar.gz .


I think this has only started happening since I've been using the '.' at the end, instead of the an '*', as that wouldn't include .htaccess.

Any ideas? Alternatively, and this is a total noob question, can I run it from outside the directory like so:
Syntax: [ Download ] [ Hide ]
tar -zcvf backup.tar.gz httpdocs/.


Would that work?

EDIT: I'm guessing actually just tar -zcvf httpdocs would do the trick...?

Thanks


Top
 Profile  
 
PostPosted: Tue Mar 20, 2012 11:18 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6587
Location: WA, USA
- The file is created while tar is going about its business. Naturally it'll find that file when it's searching the directory.
- Using * means the "searching" is done by the shell instead. Happens before tar has a chance to create the file and thus it doesn't show up.
- If you specify the directory like that then the tar will contain the httpdocs folder too - not just what it contains.

There are a handful of options but my preferences lean towards what you had before with the wildcard. If you want hidden files then include ".*" in the list.

See also: tar(1)


Top
 Profile  
 
PostPosted: Tue Mar 20, 2012 12:05 pm 
Offline
Forum Commoner

Joined: Thu Mar 10, 2011 2:03 pm
Posts: 32
That was super fast, cheers!

I wasn't sure what you meant, so I tried the following command:
Syntax: [ Download ] [ Hide ]
 tar -zcvf test.tar.gz .*


This started going a bit crazy and adding a lot of files I didn't recognise though, so I'm not sure how exactly that works. Did I misunderstand what you meant?


Top
 Profile  
 
PostPosted: Tue Mar 20, 2012 1:01 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6587
Location: WA, USA
I just realized that .* includes .. too. Try
Code:
.[^.]*

There's something else I'm forgetting that's better but, of course, I'm forgetting it. Maybe piping a file list out from find?


Top
 Profile  
 
PostPosted: Tue Mar 20, 2012 9:27 pm 
Offline
Forum Contributor

Joined: Sun Sep 09, 2007 6:27 pm
Posts: 282
With Fedora's tar you can use --exclude=backup.tar.gz to prevent the tarball from including itself.


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 10:39 am 
Offline
Forum Commoner

Joined: Thu Mar 10, 2011 2:03 pm
Posts: 32
Thanks again for the replies.

@Requinix: hmm, I think I see what you mean, but that one doesn't work on my system.

@Doug: dang, that would be perfect, but I'm running CentOS, and the exclude command isn't working.

I'll keep fiddling with it, and see if I can't get some solution. I might even just use '*' to select the files, and add .htaccess files to the tarball afterwards. That should work... I think. I'm such a noob. :D


Top
 Profile  
 
PostPosted: Wed Mar 21, 2012 2:28 pm 
Offline
Forum Contributor

Joined: Sun Sep 09, 2007 6:27 pm
Posts: 282
From a terminal do man tar to get the exact syntax. CentOS and Fedora are very similar and should support the same syntax for --exclude.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group