Add new comment
Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
|
# USERNAME
MyUSER="`cat /etc/mysql/debian.cnf | grep user | uniq | awk -F'=' '{print $2}'`" # PASSWORD MyPASS="`cat /etc/mysql/debian.cnf | grep password | uniq | awk -F'=' '{print $2}' | \ sed -e 's/^ //'`" # Hostname MyHOST="localhost" # Servername SERVER="$HOSTNAME" # mysqldump options MYSQLDUMPOPTS="--opt" # Linux bin paths, change this if it can't be autodetected via which command MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" CHOWN="$(which chown)" CHMOD="$(which chmod)" GZIP="$(which gzip)" # Backup Dest directory, change this if you have someother location DEST="/root/backups" # Main directory where backup will be stored MBD="$DEST/mysql" #create if not existing if [ ! -e "$MBD" ]; then mkdir -p $MBD fi # Get data in dd-mm-yyyy format NOW="$(date +"%m-%d-%Y")" FNAME="mysql-backup" # File to store current backup file FILE="" # Store list of databases DBS="" TMP="/tmp/$NOW" mkdir -p $TMP n=5; # the first archive number must be zero l=0; while [ ! $n -le 0 ]; do let "m = $n - 1" if [ -e $MBD/$FNAME.$m.tar.gz ]; then mv $MBD/$FNAME.$m.tar.gz $MBD/$FNAME.$n.tar.gz fi let "n = $n - 1" done # DO NOT BACKUP these databases # IGGY="test" [ ! -d $MBD ] && mkdir -p $MBD || : [ ! -d $TMP ] && mkdir -p $TMP || : # Only root can access it! $CHOWN root.root -R $DEST $CHMOD 600 $DEST # Get all database list first DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')" for db in $DBS do skipdb=-1 if [ "$IGGY" != "" ]; then for i in $IGGY do [ "$db" == "$i" ] && skipdb=1 || : done fi if [ "$skipdb" == "-1" ] ; then FILE="$db.$SERVER.$NOW.sql" # do all inone job in pipe, # connect to mysql using mysqldump for select mysql database # and pipe it out to gz file in backup dir :) $MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS $MYSQLDUMPOPTS $db > $TMP/$FILE fi done tar czvf $MBD/$FNAME.0.tar.gz $TMP &> /dev/null rm /tmp/$NOW -r exit 0
Reply |





Recent comments
21 hours 35 min ago
23 hours 4 min ago
1 day 2 hours ago
1 day 5 hours ago
1 day 8 hours ago
1 day 9 hours ago
1 day 9 hours ago
1 day 10 hours ago
1 day 11 hours ago
1 day 12 hours ago