Forum Moderators: coopster

Message Too Old, No Replies

Using PHP to backup my site

Can I tar up directories?

         

MatthewHSE

6:52 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm exploring some of PHP's FTP capabilities, and it struck me that if I could use PHP to make .tar.gz files out of a few select directories, I could make an automatic site backup system that would store backups on another web server. (I'm sure this has already been done, but I wanted to build my own for the learning experience of it.)

The problem is, I can't find out if PHP will allow you to make a .tar.gz file out of directories. Is this possible, and if so, how is it done?

Thanks,

Matthew

gliff

7:08 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



PHP has a Zlib module, but I don't believe it's compiled in by default.

[php.net ]

There are (as far as I'm aware) no functions that would allow you to create tar files with PHP. However, if you're on a Unix box (or a windows box with a tar binary), you can use the system [php.net] function to execute any command that the system understands, including tar.

Be Very Careful using the system function with values that aren't hard coded. If you don't validate your user input, someone could wry a whole lot of havoc on your (or you host's) machine.

mincklerstraat

7:23 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd have a look at the archiving classes over at PEAR - here [pear.php.net]. Don't know if they'll be worthwhile for 'heavy duty' archiving, with megs and megs, but it's worth a look.