arukiri123
arukiri123

Reputation: 141

Changing directory of PHP backup

I'm creating a script for database backing up in PHP. It's working now. My question is how do I change the directory of my backups?

This is the code:

<form action = '' method = 'POST'>
<input type = 'submit' name = "backup" value="Backup">              
</form>

<?php
    $host = 'localhost';
    $user = 'root';
    $pass = ' ';
    $dbname = 'itravel';
    $backup_name = "mybackup.sql";
    if(isset($_POST['backup']))
    {
    $backup = "c:/xampp/mysql/bin/mysqldump --opt -h $host -u $user $dbname > $backup_name";
    system($backup);
    }
?>

Upvotes: 0

Views: 105

Answers (1)

Dutts
Dutts

Reputation: 6191

At the moment your sql backup output is going to mybackup.sql which is set in the line

$backup_name = "mybackup.sql";

Try changing this value to change the output location of your backup. So something like:

$backup_name = "~/mydbbackups/mybackup.sql";

(depends on your host OS really)

Upvotes: 2

Related Questions