Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Tar file from directory in PHP without exec/passthru

So I have a client who's current host does not allow me to use tar via exec()/passthru()/ect and I need to backup the site periodicly and programmaticly so is there a solution?

This is a linux server.

like image 204
UnkwnTech Avatar asked Dec 02 '08 05:12

UnkwnTech


People also ask

Can we tar a directory?

Tape Archive or tar is a file format for creating files and directories into an archive while preserving filesystem information such as permissions. We can use the tar command to create tar archives, extract the archives, view files and directories stored in the archives, and append files to an existing archive.

How do I create a tar file in Terminal?

To create an archive with tar, use the '-c' (“create”) option, and specify the name of the archive file to create with the '-f' option. It's common practice to use a name with a '. tar' extension, such as 'my-backup. tar'.


1 Answers

PHP 5.3 offers a much easier way to solve this issue.

Look here: http://www.php.net/manual/en/phardata.buildfromdirectory.php

<?php
$phar = new PharData('project.tar');
// add all files in the project
$phar->buildFromDirectory(dirname(__FILE__) . '/project');
?>
like image 134
naitsirch Avatar answered Nov 11 '22 15:11

naitsirch