Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 12:27:56 PM

Pages: [1]   Go Down
  Print  
Author Topic: MySQL Backups Produce Empty File  (Read 539 times)
FSMN
Newbie
*
Offline Offline

Posts: 1


« on: November 30, 2011, 09:12:10 AM »

I am trying to set up a cron task to back up our database. It is modest in size (less than 3 MB), but it is important that it be backed up.  

I have created a php script to handle this, but it just produces an empty file. What am I doing wrong? (I set up a standard shell scrip to do the exact same thing with the same problem). It works just fine on my own internal LAMP server.

Code:
<?php $username 'db_user';
$host 'localhost';
$password 'password';
$database 'db_name';

$backupdate("D");
$command "mysqldump -u $username --password=$password --host=$host --database $database | gzip > $backup.sql.gz";
exec($command);


The script is designed to produce a separate backup for every day of the week, hence the $backup variable.
« Last Edit: November 30, 2011, 09:50:38 AM by FSMN » Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5220



« Reply #1 on: November 30, 2011, 03:29:09 PM »

When you run this script from the browser, does it run or fail? That would rule in/out something about cron. BTW, it should have a closing ?> (probably doesn't have anything to do with your problem, but who knows). Note that the runtime environment can be quite different between the browser and command line (cron), in case you're depending on any particular starting directory, PHP level, environment variables, etc. For cron, it's generally a good idea to explicitly give the path to all commands (mysqldump, gzip) and where the output file is written to. Also, the time the cron is using to fire off the job is LP's server time (Pacific Time).

When you say that an empty file is produced, does it have the expected timestamp (was just produced by the run), but is 0 size? That sounds like either mysqldump or gzip failed to run for some reason, or possibly the file is being placed in an unexpected directory and you're looking at an old one. Are you capturing the output from cron (in the email), and can see that this script is definitely running? What does your cron command look like? You don't appear to be using any URL Query String or command line parameters.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
BlayzeIelovich
Newbie
*
Offline Offline

Posts: 1


« Reply #2 on: December 03, 2011, 02:23:18 AM »

I want to know How  to create  MySQL backup?



Insurance Claim Broward
Logged
asindio
Newbie
*
Offline Offline

Posts: 1


« Reply #3 on: January 13, 2012, 04:27:27 AM »

Hi BlayzeIelovich,

Taking MySQL back is not a tough job.

There are 2 options to take backup of your MySQL:

1) Through Plugin (if you are using wordpress site)
2) Through Cpanel
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: