Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

mysqldump and php

  • 09-06-2008 11:22AM
    #1
    Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭


    hey i'm trying to run a mysqldump command through a php script but i'm having no joy. here's the script.

    [php]
    <?php

    include 'dbconnect.inc.php';

    $file = $DB_NAME . '_' . date("Y-m-d_H:i:s") . '.sql';

    //location of mysqldump util
    $mysqldump = '/opt/lampp/bin/mysqldump';

    $cmd = "$mysqldump --opt -h $DB_HOST $DB_NAME -u $DB_USER -p DB_PASS > $file";

    system($cmd);

    ?>
    [/php]i echoed the command and then copy and paste it into a terminal window and sure enough out popped the output file. also as far as i know system() calls aren't blocked as system('pwd') works fine.

    can anyone see anything up?


Comments

  • Closed Accounts Posts: 8 allexxei


    Check safe_mode ! If it is on - that's the problem


  • Closed Accounts Posts: 8 allexxei


    Also for $file you shoul use complete path :)


  • Closed Accounts Posts: 8 allexxei


    also, -p $password should be -p'.$password ( no space between -p and you variable) or else will promt for password


  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭Creamy Goodness


    allexxei wrote: »
    Check safe_mode ! If it is on - that's the problem

    safe_mode is Off.
    allexxei wrote: »
    Also for $file you shoul use complete path :)

    i agree, but this was just for testing purposes.
    allexxei wrote: »
    also, -p $password should be -p'.$password ( no space between -p and you variable) or else will promt for password

    fixed that, still ain't working :confused:


  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭Creamy Goodness


    ok i've changed the layout of backup.

    i now have the backup running in a perl script that runs fine and creates a mysql dump when ran from the command line, this actually works best in my favour as i now can set it up on a cron whereas i don't know if i could of done that with php due to it having to be run in a browser window.

    so i've got my backup perl script working, but i still want a html form that will allow for a manual backup of the database.

    here's the backup perl script (dbBackup.pl)

    [php]
    #!/usr/bin/perl

    use DBI;

    #MySQL login details
    my $dsn = "dbi:mysql:fat;localhost:3306";
    my $dbuser = "root"; #not using root account in real script.
    my $dbpass = "password"; #nor stupid enough to use lame password.

    #Database to backup.
    my $dbname = "fat";

    #MySQL dump directory.
    my $mysqldump = "/opt/lampp/bin/mysqldump";

    #Create dump filename
    my $fileName = $dbname;
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    $year +=1900;
    my $timeHandle = "$year-$mon-$mday"."_"."$hour:$min:$sec";
    $fileName .= $timeHandle . ".sql";

    #backup directory
    $backupDir = "./backup";


    #do mysqldump command
    my $cmd = "$mysqldump --opt -u $dbuser -p$dbpass $dbname > $backupDir/$fileName";

    print `$cmd`;
    [/php]

    which runs from from terminal.

    now here's the php script i have for the form (doesn't really need to be php but i want to keep the file extension the same as every other file in my program is php).

    [php]
    <?php

    echo'<form method="post" action="dbBackup.pl">
    <table class="admin">
    <tr><td class="admin" colspan="2"><h2>Database backup</h2></td>
    </tr>
    <tr>
    <td class="admin" colspan="2"><input type="submit" class="subbut" value="Backup DB" /></td>
    </tr>
    </table>
    </form>';
    ?>
    [/php]

    so when i submit the form i get taken to a blank page which i expect for the moment, but no backup is made?



    *EDIT* all sorted, backup directory was writable d'oh.


  • Advertisement
Advertisement