How do you back up Your database?

Discussion in 'Getting Started' started by RaceJunkie, Dec 21, 2005.

  1. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0
    I need to know the best way to do this. What I would like. Is a nightly backup saved to my server in a folder named dbBackup. I have been using a php script but I am getting errors with it on my current host, for whatever reason i do not know.

    This is what the cron.php looks like. This is in my root below public_html

    Code:
    -- Start Script Here - -
    <?php 
    $emailaddress = "mysite@gmail.com"; 
    $host="localhost"; // database host 
    $dbuser="username"; // database user name 
    $dbpswd="password"; // database password 
    $mysqldb="forums"; // name of database 
    $day = (date("d")); 
    $filename = "/home/localrac/dbBackup/" . $day . ".sql"; 
    if ( file_exists($filename) ) unlink($filename); 
    system( "mysqldump --user=$dbuser --password=$dbpswd --host=$host $mysqldb > $filename",$result); 
    $size = filesize($filename); 
    $runtime = (date(" F d h:ia")); 
    $message .= "The backup has been run.\n\n"; 
    $message .= "The return code was: $result\n\n"; 
    $message .= "Size of the backup: $size bytes\n\n"; 
    $message .= "Server time of the backup: $runtime\n\n"; 
    mail($emailaddress, "Backup Message" , $message, "From: Website <>");  
    ?> 
    - - End Script Here - - 

    This is the con job.
    This has worked fine untill I just moved my site to a new server.
    Code:
    php $HOME/cron.php >>$HOME/cron.log 2>>$HOME/cron.err
    Now this shows up in my cronlog.
    Code:
    X-Powered-By: PHP/4.4.1
    Content-type: text/html
    
    - - Start Script Here - -
    <br />
    <b>Warning</b>:  system() has been disabled for security reasons in <b>/home/localrac/cron.php</b> on line <b>11</b><br />
    <br />
    <b>Warning</b>:  filesize(): Stat failed for /home/localcom/dbBackup/19.sql (errno=2 - No such file or directory) in <b>/home/localrac/cron.php</b> on line <b>12</b><br />
     
    - - End Script Here - - X-Powered-By: PHP/4.4.1
    Content-type: text/html
    
    - - Start Script Here - -
    <br />
    <b>Warning</b>:  system() has been disabled for security reasons in <b>/home/localrac/cron.php</b> on line <b>11</b><br />
    <br />
    <b>Warning</b>:  filesize(): Stat failed for /home/localcom/dbBackup/19.sql (errno=2 - No such file or directory) in <b>/home/localrac/cron.php</b> on line <b>12</b><br />
     
    - - End Script Here - - X-Powered-By: PHP/4.4.1
    Content-type: text/html
    
    - - Start Script Here - -
    <br />
    <b>Warning</b>:  system() has been disabled for security reasons in <b>/home/localrac/cron.php</b> on line <b>11</b><br />
    <br />
    <b>Warning</b>:  filesize(): Stat failed for /home/localrac/dbBackup/20.sql (errno=2 - No such file or directory) in <b>/home/localrac/cron.php</b> on line <b>12</b><br />
     
    - - End Script Here - - X-Powered-By: PHP/4.4.1
    Content-type: text/html
    
    - - Start Script Here - -
    <br />
    <b>Warning</b>:  system() has been disabled for security reasons in <b>/home/localrac/cron.php</b> on line <b>11</b><br />
    <br />
    <b>Warning</b>:  filesize(): Stat failed for /home/localrac/dbBackup/21.sql (errno=2 - No such file or directory) in <b>/home/localrac/cron.php</b> on line <b>12</b><br />
     
    - - End Script Here - - X-Powered-By: PHP/4.4.1
    Content-type: text/html
    
    - - Start Script Here - -
    <br />
    <b>Warning</b>:  system() has been disabled for security reasons in <b>/home/localrac/cron.php</b> on line <b>11</b><br />
    <br />
    <b>Warning</b>:  filesize(): Stat failed for /home/localrac/dbBackup/21.sql (errno=2 - No such file or directory) in <b>/home/localrac/cron.php</b> on line <b>12</b><br />
     
    - - End Script Here - -
     
  2. Scribbller

    Scribbller The dude

    3,223
    760
    +1
    Just take a backup using mysql dump through SSH.
     
  3. MMM

    MMM Rent This Space...

    4,648
    605
    +12
    If you're on vB then I think theres a hack that does this. I haven't tried it though so I can't give you a review. We're at Site5 and we use their NetAdmin instead.
     
  4. Wayne Luke

    Wayne Luke Tazmanian

    5,793
    0
    +35
    If you are on vBulletin, there is a Shell Execution script (vb_backup.sh) provided to do this in the "Do Not Upload" folder. Quick, easy and it even GZIPs the backup. Maybe other forum packages provide the same...

    I wouldn't recommend a hack within the forum system itself. Talk about unnecessary use of Web Server resources.

    The errors are caused because the host you are on now has disabled those functions in PHP for security. This is actually common on Shared Hosts.
     
  5. Homerun

    Homerun vB User

    182
    0
    +0
    For vBulletin, how would we go about using that vb_backup.sh?
     
  6. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0

    I am running vB ( i should have mentioned this) and I will look in this folder tonight when i get home. Are there instructions on how to run it and what command to use in the cron tap? The only reason I was using this cron.php is beacause it was simply laid out for me.
     
  7. PalePhoenix

    PalePhoenix Prince of Dorkness

    11,988
    650
    +29
    I have a dozen blind monks who work tirelessly transcribing each table and semi-colon in Braille on the flesh of kittens.

    j/k. I do what Scribbller does, and also keep local copies of all XML, including skins and whatnot. We use IPB. I pretty much have the whole site, in pieces-parts on my home drive. It's just a backup to a backup, since our host also does this for us daily (few do, so check with yours).
     
  8. Wayne Luke

    Wayne Luke Tazmanian

    5,793
    0
    +35
    Should just have to mark the file as an executable for the crontab user and make a crontab entry for it.
     
  9. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0
    See this is what I mean. I really don't understand what you are talking about.

    How? what file?

    What would I enter?

    where do i place the file or files?
    Will it do a daily back up and put it in a named directory?
     
  10. instanthosting

    instanthosting Enthusiast

    166
    0
    +0
    If you run through Cpanel , it is easy enough to backup through that, go to MYSQL and back the files up, its easy enough
     
  11. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0
    I am looking an automatic way of doing this. What if i am away for a week. I need something to keep my db updated.
     
  12. Wayne Luke

    Wayne Luke Tazmanian

    5,793
    0
    +35
  13. MMM

    MMM Rent This Space...

    4,648
    605
    +12
    Site5 is the only host that has this feature built-in. It's called "Flashback" and you never have to do a thing, it automatically backs up every single file in your account, and as if that isn't great enough, it doesn't use any of your server space to do this :) If you ever need a file you just simply click on it and *poof* it's restored. Life is good :D
     
  14. RockyB

    RockyB Participant

    92
    6
    +0
    This is one advantage of phpBB. You can backup your database in two clicks. I don't know if it can be done automatically though.
     
  15. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0
    So the correct CHMOD would be 744?

    I understand the time part of the cron but as to what I enter to make cron execute the file, I'm at a brick wall.
    Right now i have vb_backup.sh stored in the root.
    Is this acceptable?
     
  16. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0
    Been there done that and aint going back. But thank you very much. I was actualy running one of B&T's scripts but my current host does not allow it since it makes use of the system and say it is a security thing. That script worked great at Site5 but not now.
     
  17. GeorgeB.

    GeorgeB. ............

    3,906
    952
    +110
  18. Sculli

    Sculli Custom User Title

    648
    0
    +0
    My host does a nightly off-server backup of all my stuff, including the DB, so I don't need to worry about it. Just putting that out there as an option.
     
  19. hugh

    hugh Adherent

    376
    138
    +0
  20. RaceJunkie

    RaceJunkie Aspirant

    20
    0
    +0
Verification:
Draft saved Draft deleted