Backing up Database

I am trying to find the best way to backup my database. I originally wanted to set it up so that the database would dump to an email sent to me nightly, but i am not really even sure where to begin with that. so I set the following code up, but it is giving me an error as well. Would love a hand with this, or even better a pointer on how to get the database dumped to an email nightly so i dont have to do it manually!

Heres the error:
Fatal error: Function name must be a string in C:\wamp\www\invdb\includes\backup.php on line 5
and the code:
[php]

Choose Data To View
Completed Orders
Current Orders
Production
Recieving
Shipping

<?php if (!isset($_POST['db_chooser'])) { //If not isset -> set with dummy value $_POST['db_chooser'] = "undefine"; } else { $choice=make_safe($_POST['db_chooser']); include('includes/backup.php'); } unset($_POST['db_chooser']); ?>[/php]

Backup.php
[php]<?php

$tableName =make_safe($_POST(‘db_chooser’));
$backupFile = ‘backup/’ . $tableName . ‘.sql’;
$query = “SELECT * INTO OUTFILE ‘$backupFile’ FROM $tableName”;
$result = mysql_query($query); ?>[/php]

If you want to use a pre-written solution there is MySQL Dumper from http://www.mysqldumper.net/ it is free.

Hi Journeyman1900,

The problem is with this line:[php]$tableName =make_safe($_POST(‘db_chooser’));[/php]

It should be:[php]$tableName =make_safe($_POST[‘db_chooser’]);[/php]

Darn brackets!

Let me know if that doesn’t resolve it.

That is way to complicated… Try this

Here is my implementation

Cron job (crontab -e)

@hourly LOCATION_OF_YOUR_SCRIPT/backup.sh or* */1 * * * LOCATION_OF_YOUR_SCRIPT/backup.sh

Then you need a shell script mine looks like this

#!/bin/sh DATE=$(date +%m-%d-%Y_%H:%M:%S) mysqldump -u USERNAME -p'YOURPASSWORD' --all-databases > /services/web/database_backups/$DATE.sql gzip -f /services/web/database_backups/$DATE.sql

this runs Hourly but a simple search on cron scheduling and you can run it when ever you like and all you would have to do is write another shell script or php script to email yourself the file. You could also do this in an exex() command if you do not have access to cron. Or you can use a free cron service there are several out there.

Keep in mind that database files can get fairly large so emailing it could be come cumbersome.

Thank you Guys!

Sponsor our Newsletter | Privacy Policy | Terms of Service