0

I am trying to backup a MySQL database called Reserveboxto a .gzip file. I got this script from a tutorial, and I changed the values according to my values. The problem is when I click submit nothing happens. I do not know where did I go.

<form id="form1" name="form1" method="post" action="backup.php">
    <input type="submit" name="Backup" id="Backup" value="Backup" />
</form>

<p>&nbsp;</p>

<?php
    include ("functions_cp/f_connection.php");
    Sqlconnection();

    $dbname = "Reservebox";
    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "123";

    function backup() {
        $backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
        $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
        system($command);
    }
    if(isset($_POST['backup'])) {
        backup();
    }
9
  • Why don't you BACKUP using PHPMyAdmin ? Its super-easy ! Jan 31, 2012 at 22:30
  • check logs. Perhaps your PHP config doesn't allow using system
    – Alfabravo
    Jan 31, 2012 at 22:30
  • i do know who gives me -1 but OK ! , @sh4nx0r i need to learn how ! I KNOW THAT I CAN USE PHPMYADMIN :) Jan 31, 2012 at 22:32
  • Are there any shell metacharacters &^$;|>< in your password or database name? Does your webserver have privileges to write directly in its current working directory? (Almost certainly not. If it does, I'd say that is probably a misconfiguration that is asking for a security flaw.)
    – sarnold
    Jan 31, 2012 at 22:33
  • @BaderHAlRayyes, I never downvote , so grab some H20. Jan 31, 2012 at 22:34

2 Answers 2

1

if(isset($_POST['backup'])) { I think the backup on this line needs a capital B!

If that doesn't sort it, try adding error_reporting(E_ALL); on a new line after <?php.

3
  • after i added the error_reporting , it gives me this "Notice: Undefined variable: dbname , and all other vars with same message , i put them all inside the function backup , the error gone but also nothing happens agains , it appears the when i click the button something loads for a bit but no file to download. Jan 31, 2012 at 22:47
  • 1
    The notices are okay. The code you have shown us doesn't show that a file is meant to be returned. It's going to write a .gz file to the file system. You should go look for it :)
    – jon
    Jan 31, 2012 at 22:54
  • i changed the type to .sql and it worked , however the file i generate is empty, any suggestions ? Jan 31, 2012 at 23:07
1

Try removing the space between the -p and $dbpass.

Also, remove --opt. That is not strictly necessary.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.