Compress Query to Tar

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
luyznascimento
Forum Newbie
Posts: 10
Joined: Wed Apr 04, 2007 9:46 am

Compress Query to Tar

Post by luyznascimento »

Hi,


I am new to this FORUM and I hope to count with your precious support. I am trying to, after querying data from a DB, create on the fly "a tar file on my server". Is it possible?

My site is located on a Linux server.

I looked around the web for a solution but the possibilities found became frustrating.

Thank you for your attention.

LuyzNascimento
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().
luyznascimento
Forum Newbie
Posts: 10
Joined: Wed Apr 04, 2007 9:46 am

Post by luyznascimento »

feyd wrote:Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Hummmmmmmmmmmmm...nice try. I will do it now and see what happens! I will try not to explode anything with this :-))))


Kind Regards,
Luyz Nascimento.
luyznascimento
Forum Newbie
Posts: 10
Joined: Wed Apr 04, 2007 9:46 am

Post by luyznascimento »

luyznascimento wrote:
feyd wrote:Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Hummmmmmmmmmmmm...nice try. I will do it now and see what happens! I will try not to explode anything with this :-))))


Kind Regards,
Luyz Nascimento.

No it does not work. I tried so many different things since then but I just round and round...now where to go?

Far from now I tried to learn shell programming. I became with the following:

Code: Select all

#!/bin/sh
#

if test -z $1

then

        echo "empty directory - please inform one..."

else

        cd "$1/"

        tar -cf "$1.tar" cbq*

        #ls -al
fi
I call the above statement with:

Code: Select all

shell_exec ('. cd.sh DirName');
But nothing happens the way I expected it to throught SHELL_EXEC WITHIN PHP. But, instead, if I call that file over telnet prompt - works perfectly. It changes to the dir informed like: [root@controle tar]# . cd.sh DirName -, and do the rest of command...

Any suggestions?

Luyz Nascimento
luyznascimento
Forum Newbie
Posts: 10
Joined: Wed Apr 04, 2007 9:46 am

THE ANSWER OR WAY OUT AS U PREFER...

Post by luyznascimento »

luyznascimento wrote:
luyznascimento wrote:
feyd wrote:Unless my memory is failing, you would simply write the data to a file then call tar via system(), exec() or shell_exec().

Guys and Girls,


After a long time searching, seeking, willing this information, this morning here in my bedroom, I woke up with something strange living in my ideas...so I got this happening:

1 - I seeked if PHP would have a function to CHANGE DIRECTORY - YES IT HAS: CHDIR("DIRECTORY_NAME"). With this I changed the way things acts - I was trying to execute the "CD" command line from linux into SHELL_EXEC - won t work as expected to. = WRONG WAY !!!

2 - With the new code on my hands I needed to develop a simple condition to discover if UNDERSTANDS the change directory situation and WORKED!!!

3 - the rest was only success and I DIVIDE IT WITH YOU BELOW, BECAUSE IT WAS NOT A WASTED OF TIME ANYWAY - AS WE CAN SEE - I LEARNED AND TRY TO SAVE YOUR TIME EITHER, TEACHING YOU? Well its up to you, I guess.

Code: Select all

The "$dir" variable - comes dynamically on my code, ok?

if (chdir("$dir/")){

shell_exec ('tar -cf '.$dir.'.tar cbq*');

}

Kind Regards,
Luyz Nascimento
Post Reply