Results 1 to 3 of 3

Thread: Mysql Backup

  1. #1
    Join Date
    Apr 2004
    Posts
    2

    Red face Unanswered: Mysql Backup

    i have 4 database

    DB1
    DB2
    DB3
    DB4

    And i need to backup them with mysqldump but not all of them in one file. I need 4 different files.

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    So what is the question? Use mysqldump on each and use a different filename for each of the dumps.

  3. #3
    Join Date
    Feb 2004
    Posts
    4
    Code:
    #!/bin/sh
    
    # MySQL hostname
    DBHOST='hostname'
    
    # MySQL username
    DBUSER='user'
    
    # MySQL password
    DBPASSWD='password'
     
    # directory to dump backups to
    DESTDIR=/path/to/backup
    
    # format todays date
    TODAY=`date +%Y-%m-%d`
    
    # create directory for todays backup if needed
    if [ ! -e $DESTDIR/$TODAY ]; then
        mkdir $DESTDIR/$TODAY
    fi
    
    # get all databases
    DBS=`mysql -u$DBUSER -p$DBPASSWD -h$DBHOST -e"show databases"`
    
    for DATABASE in $DBS
    do
        if [ $DATABASE != "Database" ]; then
            # let's put date here too in case archives get moved around later on
            FILENAME=$TODAY-$DATABASE.gz
            mysqldump -u$DBUSER -p$DBPASSWD -h$DBHOST $DATABASE | gzip --best > $DESTDIR/$TODAY/$FILENAME
        fi
    done
    
    exit 0

Posting Permissions

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