1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Database backup?

Discussion in 'MySQL' started by trinh, Aug 2, 2005.

  1. #1
    Hey, I have a couple of databases under my "management" but I do not have phpMyAdmin or any other similar tool.

    All I want to know is what code would I use (preferably PHP) to download a backup of these two databases.

    What I want is for when this page is opened it to start a download of a database copy, ideally in .sql or .txt format.

    Any ideas?

    Or if this is not possible would it be possible to make the following script copy the backup to a directory?

    Many thanks for any replies
     
    trinh, Aug 2, 2005 IP
  2. mopacfan

    mopacfan Peon

    Messages:
    3,273
    Likes Received:
    164
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What kind of databases are they? mysql? mssql????
     
    mopacfan, Aug 2, 2005 IP
  3. trinh

    trinh Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry, forgot :p

    It is a MySQL database. I believe the MySQL version is somewhere in the 4's as is PHP.
     
    trinh, Aug 3, 2005 IP
  4. stickman373

    stickman373 Peon

    Messages:
    331
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why not just put a copy of phpMyAdmin on the server, it's free and easy to backup and restore then
     
    stickman373, Aug 3, 2005 IP
  5. forkqueue

    forkqueue Guest

    Messages:
    401
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you've got shell access you can use the mysqldump tool.
    With SSH keys you can write a script which will log in and backup up automatically.
    phpMyAdmin is a better choice if you're not down with the command line.
     
    forkqueue, Aug 3, 2005 IP
  6. plmerlin

    plmerlin Guest

    Messages:
    490
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    118
    #6
    plmerlin, Aug 3, 2005 IP
  7. my3cents

    my3cents Peon

    Messages:
    332
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I use the mysqldump tool (comes with mysql) and the ftp the file(s) to another server. Two simple commands in a script will do it. The use cron to schedule it nightly or weekly, whatever suits you.

    Don't have the commands with me, I will post them later if I get a chance.
     
    my3cents, Aug 3, 2005 IP
  8. my3cents

    my3cents Peon

    Messages:
    332
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Here is the script to backup your db in mysql into a gzip file:

    mysqldump -h www.yourserver.com -p dbname | gzip >/home/db_bk/mysql-db.gz
     
    my3cents, Aug 3, 2005 IP
  9. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #9
    and check the mysqldump documentation, there are a lot of flags you can use to make it easier to restore a backup, or to make it dump faster, or to sort data etc.

    what I do is running a cronjob at low-load hours (4:30AM) that dumps all databases and all tables to seperate zip files. the name of these files are
    [database]/[table]/[day-of-the-week].dump.gz , where day-of-the-week is (Mon,Tue etc).
    that gives me a backup of all data on the server the mysqld is running on. Make sure you save the backups on another disk (hardware! not partition) as the real mysql data is on. that will help you when a drive crashes (And trust me, they do)

    then I got another server, that uses rsync to mirror the dump directory from the initial server. That is also a cronjob, ran every 4 hours (just to be sure I get the data as soon as possible)

    to give you a detailed picture: I've got 4 servers, on 3 differenet networks that are all creating dumps locally, and all 4 are rsyncing the others.

    --
    when do you need to re-install a backup? when you just figured out there ARE no backups
     
    frankm, Aug 3, 2005 IP
  10. trinh

    trinh Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks for the help.

    I will try installing phpMyAdmin again.

    Incase that don't work. Will this be the correct script to save the backup in the directory "games":

    <?php


    mysqldump -h w.myserver.com -p dbname | gzip >/home/public_html/games/mysql-db.gz;

    ?>

    Or will that not work. Sorry to keep asking, I really am new to all this :(

    EDIT: Had to remove the www from my domain as I need more posts to post links :confused:
     
    trinh, Aug 4, 2005 IP
  11. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
  12. trinh

    trinh Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Many, many thanks for that link. Does just what I want :D
     
    trinh, Aug 7, 2005 IP
  13. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
    #13
    That's my site btw.
     
    RectangleMan, Aug 10, 2005 IP
  14. Shoemoney

    Shoemoney $

    Messages:
    4,474
    Likes Received:
    588
    Best Answers:
    0
    Trophy Points:
    295
    #14
    double word score ;)
     
    Shoemoney, Aug 15, 2005 IP