1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

need feedback on linux backup script

Discussion in 'Linux / BSD / Mac OS X' started by wiak, Apr 9, 2013.

  1. wiak

    wiak

    Joined:
    Sep 5, 2004
    Messages:
    1,743 (0.48/day)
    Thanks Received:
    198
    Location:
    Norway
  2. W1zzard

    W1zzard Administrator Staff Member

    Joined:
    May 14, 2004
    Messages:
    14,752 (3.93/day)
    Thanks Received:
    11,466
    simple enough. please be aware that mysqldump will lock your databases for while it runs.

    might want to consider gzip with lower compression for more throughput

    i also recommend to split the database dumps into one file per database.. MUCH easier to restore individual stuff then

    Code:
    #!/bin/bash
    
    umask 0077                                                                                                                                                                                
    # MySQL Login details
    MYSQLUSER="root"
    MYSQLPASSWORD=""
    
    for DATABASE in `echo 'show databases' | mysql --column-names=false --password=$MYSQLPASSWORD`
    do
    #        echo -n "Exporting database $DATABASE to $DATABASE.sql ... "
            /usr/bin/mysqldump --quick --add-drop-table --add-locks \
                    --extended-insert --password=$MYSQLPASSWORD \
                    --user=$MYSQLUSER --opt $DATABASE | gzip -f -9 > $DATABASE.sql.gz
            /bin/chmod 600 $DATABASE.sql.gz
            BYTES=`stat -c "%s" $DATABASE.sql.gz`
            BYTES=`echo "scale=2; $BYTES/1024" | bc`
    #        echo "Compressed to $BYTES KBytes."
    done
    
    we use that on a replication slave so it doesn't lock our main database

    google rsnapshot for a wonderful free general purpose backup tool
  3. wiak

    wiak

    Joined:
    Sep 5, 2004
    Messages:
    1,743 (0.48/day)
    Thanks Received:
    198
    Location:
    Norway
    cool danke! :)
    /ich jaster ein beer @ w1zzard

    trying out memrise.com :p
    sorry if i offend you with my deutch

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page