Page 1 of 1
How to tar a directory?
Posted: Sat Apr 01, 2006 4:29 pm
by Sinemacula
I've done a search here and discovered that I can't gzip a whole directory - that I have to tar it first... but I can't seem to find any examples of how to tar a directory.
Ideally, I'd like to tar the directory, then gzip it appending the date to the filename, and place the gzip file in another directory.
Any pointers or sample code I could use as a start?
Thanks,
Scott
Posted: Sat Apr 01, 2006 4:34 pm
by timvw
What's not explained in man tar?
Here's how i do it:
Code: Select all
# generate tar-gzipped archive of homedirectory
tar -czf /tmp/backup.tgz ~
# move backup to homedirectory and change name
mv /tmp/backup.tgz ~/madoka-`date +%F`.tgz
Posted: Sat Apr 01, 2006 4:57 pm
by Sinemacula
Thanks, timvw...
I hadn't looked at the man entry (not being much of a command-line user, it didn't occur to me)... but does it show how to make that work in a php script?
Here are some more details to help clarify what I'm looking for:
I've got a php script that pulls data from a mysql database and creates a separate file for each record and puts them all in directory1. What I want is for that same script to then tar and gzip directory1 and put the resulting archive in directory2.
Ideally, the script will then delete all the individual files in directory1 (but leaving directory1 itself).
So, what I need is to know if this is possible within a php script?
I have found some sample php code that will allow me to gzip a file and put the archive in a different directory, but I need something that will do a whole directory.
Thanks,
Scott
Posted: Sat Apr 01, 2006 6:44 pm
by feyd
Moved to .. Linux!

Posted: Sat Apr 01, 2006 11:18 pm
by Sinemacula
Actually, although the answer was for the command line, what I was looking for was php code.
However, the problem has been solved by the zip class in Code Snippets (which you pointed me to in another thread - thanks!)