Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
"be consistent"
 
PerlMonks  

MySQLdump via Web

by packetstormer (Monk)
on Aug 12, 2011 at 14:01 UTC ( #920029=perlquestion: print w/ replies, xml ) Need Help??
packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am trying to figure out a way to preform a mysqldump command via a webpage. Does anyone know of any modules that might help?

At the moment I am running into permission problems when creating the output file as the www-data user doesn't have rights to write the file. Does anyone have a secure, trick for passing a parameter to make the www-data have the permissions? I was thinking of invoking the "su" command with a command line and password but I am unsure if this is the way to go.


Does anyone have any suggestions?

Comment on MySQLdump via Web
Re: MySQLdump via Web
by moritz (Cardinal) on Aug 12, 2011 at 14:06 UTC

    The trick is to write to a directory where you have permissions. Usually /tmp/ does the trick, or you can set up a directory with write permissions in advance.

    It really depends on your use case what solution is the best.

    From a security perspective it is best to avoid giving www-data write permissions to any directories that web server uses (for configuration or as a document root)

Re: MySQLdump via Web
by sundialsvc4 (Monsignor) on Aug 12, 2011 at 16:18 UTC

    I think that this is the right place to use a batch-processing system.   The web site would be able to “submit a request” to that system to do this particular thing.   The work itself would be carried out by that system, which would also be responsible for regulating how many such requests could actually be in-progress at any one time.   The web-page (and by extension, the web server) is merely a user interface to getting such things started and/or for monitoring their status.   Said web-server has, and is not given, any direct control over the situation.

      ++ on that. When your dump starts taking longer, you'll have to deal with web client timeouts, users getting bored and killing their browser instead of waiting around, network glitches cutting off clients, etc, etc, etc...

      Even if it's just backgrounded... big difference. Initiate request for me, let me know if its done, and possibly give me a way to stop it if its not done.

      --Dave

      ++ to batch processing.

      The way I would do it is to have a simple CGI script on the server that sets a flag to indicate that a dump has been requested by writing an empty file to a certain place. (After checking that the requesting user is authenitcated, and has the right to request a dump.)

      Then have a cron job that runs every few minutes as a more privalaged user. If the flag is present it can do the dump and write it to a location that the web server can read. If there is no flag, or the last dump was to recent then it exits immedately.

      From the end user's point of view the process is to visit a special web page, enter a username and password, then wait 5 minutes or so before downloading the result.

Re: MySQLdump via Web
by Anonymous Monk on Aug 15, 2011 at 11:36 UTC
    Heh. MVS taught us all about batch processing systems and then Unix came along and taught us to forget everything that we had ever learned; that cron-jobs running every five minutes were the only way to go. Not true. Unix/Linux has plenty of good batch workload managers, all free. Use one. CPAN has all the tinker-toy parts, too. Use 'em. None of 'em require JCL and //JOB cards...

      This sounds like the voice of experience ;-)

      At this point we are using cron. But I have to agree that cron is not the only way and can stomp on you. If you are using a web server make sure you use authentication. You don't want just anyone to execute it. I have a Apache web server using Perl CGI with an admin page that is restricted, no sticky fingers if you please!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://920029]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-04-23 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (554 votes), past polls