+ Reply to Thread
Results 1 to 3 of 3

Thread: Automatic MySQL Backup Script

  1. #1
      Associate canela
    Join Date
    Nov 2006
    Posts
    28

    Automatic MySQL Backup Script

    I modified crouse’s mysql backup script with some modifications and have been using it for a few weeks. It saved my tush yesterday, so I thought I’d share it.

    It stores backup files in the directory /var/backups/mysql that it automatically creates. It also only backs up if MySQL is running by checking for the lock file.

    The nice thing about it is that you don’t have to specify the names of the databases. It figures it out by itself.

    Stick it in cron, and make sure you have enough space in /var !

    You run it like this:

    Code:
    # mysql-backup <root-username> <root-password>
    The code looks like this:

    Code:
    #!/bin/bash 
    LOCK_FILE="/var/lock/subsys/mysqld"
    # Create the backup directory if it doesn't already exist
    if [ ! -d /var/backups/mysql ]; then
         mkdir -p /var/backups/mysql
    fi
    # Do backups
    if [ -f "$LOCK_FILE" ]; then
        # Do MySQL backups
        for i in `/usr/bin/mysql -B -u $1 -e 'show databases' -p$2 | /bin/grep -v Database`; do
            /usr/bin/mysqldump --opt -u $1 -p$2 $i | gzip > /var/backups/mysql/$i.`date --iso-8601`.sql.gz
        done
    fi

  2. #2
      Good Guru trickster trickster's Avatar
    Join Date
    Mar 2002
    Posts
    4,147
    Thanks!

    Perhaps we should add this to the Wiki?
    My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive.

  3. #3
      Associate canela
    Join Date
    Nov 2006
    Posts
    28
    OK, it’s done! You can find it here.

+ Reply to Thread

Similar Threads

Replies: 5
Last Post: 11-11-2006, 11:23 PM
  • Redhead, finally finished backup script
    By vwgtiturbo in forum Programming
    Replies: 0
    Last Post: 06-28-2006, 03:42 PM
  • Rsync incremental backup script
    By vwgtiturbo in forum Programming
    Replies: 6
    Last Post: 06-07-2006, 09:19 PM
  • How to Use Windows Backup to Backup Your Data
    By The Donald in forum Windows – General Topics
    Replies: 0
    Last Post: 01-04-2005, 10:37 PM
  • mysql installation instructions & permissions
    By elovkoff in forum Linux – Hardware, Networking & Security
    Replies: 2
    Last Post: 02-06-2002, 11:51 AM
  • Bookmarks

    Bookmarks

    Posting Permissions

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