Results 1 to 4 of 4

Thread: MySQL Backup Script

  1. #1
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145

    Cool MySQL Backup Script

    Hi

    For those who are interested, I have created a little perl script to backup a MySQL database.

    The script can be found here. ( actual script here )

    Working:

    You first need to configure it, by editing the file. Things you should change:

    $use -> your MySQL username
    $password -> your MySQL password

    Note : You should use a username that have access to all tables.

    The script will then gather the info of all databases ( excluding the mysql db ) and dump the content ( valid SQL statements ) to standard output ( stdout ).

    You should call the script like this:

    prompt> mysqlbackup.pl > backupfile.sql

    The reason I did not include the mysql db are numerous, so you should backup that manually, especially the user table.

    When you need to restore the database, just call the backup.sql file from the mysql client, or use phpMyAdmin.

    I hope this helps somebody

    itfirms.co.za

  2. #2
    Join Date
    May 2004
    Posts
    4
    Links where broken but this is a script that I use in crontab.

    #! /bin/bash
    mydate=$(date +%m%d%Y%I%M%p)
    PATH=$PATH:/usr/local/bin
    export PATH

    /usr/local/mysql/bin/mysqldump --flush-logs --opt -u USERNAME -pPASSWORD DBNAME > /dir1/dir2/dir3/backup.sql
    cd /dir1/dir2/dir3/

    if [ -e backup.sql ]
    then
    tar -czvf $mydate-sqlback.tar.gz backup.sql
    fi
    if [ -e $mydate-sqlback.tar.gz ]
    then
    lftp <<EOF
    open FTP SERVER
    user USERNAME PASSWORD
    pwd
    put $mydate-sqlback.tar.gz
    bye
    EOF
    fi
    if [ -e backup.sql ]
    then rm /dir1/dir2/dir3/backup.sql

  3. #3
    Join Date
    Sep 2003
    Posts
    6
    ...but, isn't that the same thing as mysqldump?

  4. #4
    Join Date
    May 2004
    Posts
    4
    Well....yes it is. I only posted that b/c the links in the first post were broken, its a fairly safe and simple way to backup your db.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •