Forum Moderators: coopster

Message Too Old, No Replies

folder backup scripts

         

jackvull

1:36 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



Any scripts out there to backup all folders in the root, zip it, and email it out?

eelixduppy

2:46 pm on Jul 15, 2008 (gmt 0)



I wouldn't be doing this with PHP directly; it wouldn't be the best method. I would run one of the Execute Functions [php.net] and just zip your root directory through the command line. This will certainly be much faster and, well, easier to write :)

jackvull

3:55 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



Have tried this, it doesn't seem to do anything.
Nothing is reported back in the variable.
Safe mode is definitely off.
Any ideas?
<?php
$c_pid = exec("tar -zcvf test.tar.gz /home/sub2/sc83-LG");
echo $c_pid;
?>

janharders

4:03 pm on Jul 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's what it should do ... exec returns the last line of output from the program ... tar won't output anything if everything works fine.
try system instead.
is the file created? and I'd advise on using an absolute path for the file ... you never really know the current working directory.

jackvull

4:21 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



No file created.
I added retval and it returns a code of 2:

$c_pid = system("/bin/tar -zcvf /mounted-storage/home/sub002/sc11883-LGVN/test.tar.gz /mounted-storage/home/sub002/sc11883-LGVN", $retval);
echo "CPID:".$c_pid."<br />";
echo "Return:".$retval;

janharders

11:41 pm on Jul 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mh, is $c_pid FALSE or an empty string?
A site says, 2 would mean "2 - internationalization error that should never occur, checksum error"

which would be quite weird to run into.
can you execute other programs without problems?
try something along

$c_pid = system("ls -ld /mounted-storage/home/sub002/sc11883-LGVN", $retval);
echo "CPID:".$c_pid."<br />";
echo "Return:".$retval;

[edited by: eelixduppy at 11:54 pm (utc) on July 15, 2008]
[edit reason] removed URL [/edit]

jackvull

8:57 am on Jul 16, 2008 (gmt 0)

10+ Year Member



ls works.
Following code

<?php

$c_pid = system("/bin/tar -zcvf /mounted-storage/home10/sub002/sc11883-LGVN/test.tar.gz /mounted-storage/home10/sub002/sc11883-LGVN", $retval);
echo "CPID:".$c_pid."<br />";
echo "Return:".$retval."<br />";

$c_pid = system("/bin/ls -ld /mounted-storage/home10/sub002/sc11883-LGVN/", $retval);
echo "CPID:".$c_pid."<br />";
echo "Return:".$retval;
?>

returns


CPID:
Return:2
drwx--x--x 7 sc11883-LGVN 2850 4096 Jul 15 17:04 /home10/sub002/sc11883-LGVN/ CPID:drwx--x--x 7 sc11883-LGVN 2850 4096 Jul 15 17:04 /home10/sub002/sc11883-LGVN/
Return:0

janharders

9:37 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



but again, no file is created, I take it?
what could be possible (if you're working with mod_php and not suphp) is that the local user running the scripts (www-data for example) is not allowed to write in the directory. have you tried to put it somewhere else or chmod the folder so that the user may write?
at least you got the execute-part running, now you just have to test what to do to get the command to work.

jackvull

10:14 am on Jul 16, 2008 (gmt 0)

10+ Year Member



Not really, I have no idea what is wrong.
I need to debug it and see the error messages but there doesn't appear to be a way of doing that.

I change the script to dump the file in a folder that I know it can write to but it gives the same return value of 2.

janharders

10:34 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try adding "2>&1" at the end of the tar-command. maybe it's telling you something on stderr that system(), returning stdout, isn't seeing.

jackvull

11:14 am on Jul 16, 2008 (gmt 0)

10+ Year Member



It now creates the tar file but it's only 45bytes, which is no where near what it should be:
/bin/tar: Removing leading `/' from member names /bin/tar: /mounted-storage/home10/sub002/sc11883-LGVN: Cannot savedir: Permission denied /bin/tar: Error exit delayed from previous errors CPID:/bin/tar: Error exit delayed from previous errors

jackvull

11:17 am on Jul 16, 2008 (gmt 0)

10+ Year Member



aha!
I needed a forward slash on the end!

jackvull

11:22 am on Jul 16, 2008 (gmt 0)

10+ Year Member



problem is that it has to be in the same folder, I can't move the backups to the root in the tar command?

Maybe I just do that with php

jackvull

11:26 am on Jul 16, 2008 (gmt 0)

10+ Year Member



I have to chmond the folder to 777, which doesn't seem good ?

janharders

11:55 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



why can't you move the backups to the root-folder with tar? you can supply any file to be written to, as long as it's writable.

chmod 777 is not the best thing, but shared hosting with mod_php often makes it necessary. mod_php in shared hosting is always a security issue.