Meidokon Wiki
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Useful(?) links

  • furinkan's stuff

  • Postfix snippets


  • SystemInfo

  • This sidebar

Navigation

  • FrontPage
  • RecentChanges
  • FindPage
  • HelpContents

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

MeidokonWiki:
  • mysqldump_for_backups

mysqldump for backups

Making it awesome!

  • mysqldump --quick --complete-insert --quote-names mysql | gzip > dump.gz
  • logrotate fragment

    /var/lib/backup/mysql/*.gz {
            daily
            rotate 2
            nocreate
            missingok
    }
  • the script

    #!/bin/bash
    #
    # Backup the entire MySQL
    #
    
    MY_BACKUP=/var/lib/backup/mysql
    LOGROTATE_BINARY=/usr/sbin/logrotate
    LOGROTATE_FRAGMENT=/tmp/mysqldump_logrotate.tmp.conf
    GZIP_BINARY=gzip
    # Once upon a time we tested using pigz, but it doesn't support --rsyncable
    # This is important, because lots of our servers use rdiff-backup
    # Maybe pigz will support it in future - <barney@anchor.net.au> 2010-06-17
    #if which pigz >/dev/null ; then GZIP_BINARY=pigz ; fi
    
    if [ ! -d $MY_BACKUP ]
    then
            mkdir -v -p -m 0700 $MY_BACKUP
    fi
    
    if [ ! -d $MY_BACKUP ]
    then
            echo "ERROR: database backup directory '$MY_BACKUP' does not exist." 1>&2
            exit 1
    fi
    
    
    # Compress data in an rsync-efficient manner, if possible
    # This extra test is for pigz, as it dies if it even smells the GZIP env-var
    if [ x$GZIP_BINARY == x'gzip' ] ; then
            if gzip --help | grep -q -- --rsyncable
            then
                    # gzip reads this environment variable automatically
                    export GZIP="--rsyncable"
            fi
    fi
    
    
    # rotate the old one out, clears the way for mysqldump.gz
    cat > $LOGROTATE_FRAGMENT <<EOF
    /var/lib/backup/mysql/*.gz {
            daily
            rotate 2
            nocreate
            missingok
    }
    EOF
    $LOGROTATE_BINARY -f $LOGROTATE_FRAGMENT
    rm -f $LOGROTATE_FRAGMENT
    
    
    # do the dump
    /usr/bin/mysqldump --quick --complete-insert --all-databases --quote-names | $GZIP_BINARY > $MY_BACKUP/mysqldump.gz
    
    
    # Purge the binary log
    # This could/should be templated for puppetised systems
    if /usr/bin/mysqladmin variables | grep -q log_bin.*ON
    then
            /usr/bin/mysql -e 'RESET MASTER;'
    fi
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01
MoinMoin Release 1.9.11 [Revision release], Copyright by Juergen Hermann et al.