Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Steps for Successful Backup and Recovery Using MySQL Enterprise Backup

Uploaded by

postgretraining
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Steps for Successful Backup and Recovery Using MySQL Enterprise Backup

Uploaded by

postgretraining
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Steps for successful Backup and Recovery using MySQL Enterprise Backup.

1. Create a Backup directory and change owner to mysql user.

# mkdir /backup

# chown mysql:mysql /backup

2. Create a MySQLBackup group in my.cnf file and also add innodb info in mysqld section.

[mysqld]

innodb_log_files_in_group=2

innodb_log_file_size=512M

innodb_data_file_path=ibdata1:76M:autoextend

#make ensure that the file size should exactly match with your current ibdata1 file.

[mysqlbackup]

backup-dir=/backup

socket=/var/lib/mysql/mysql.sock

3. Restart Mysql service.

# service mysql restart

4. Take the full backup :

# mysqlbackup --defaults-file=/etc/my.cnf -p backup-and-apply-log

5 If it executed success fully then perform next step else troubleshoot the problem.

6. Stop the mysql service.

# service mysql stop

7. Remove following files from /var/lib/mysql directory.

a) ibadat1

b) ib_logfile0

c) ib_logfile1
# also ensure that the owner of every file and folder in /var/lib/mysql is mysql user.

8. Run the recovery backup.

# mysqlbackup --defaults-file=/etc/my.cnf copy-back

9. If it is OK then start the mysql service else troubleshoot.

# service mysql start

10. Check your data by logging into mysql.

Incremental backup

Start lsn is the “ end lsn “ values copied from you last backup dir/meta directory’s backup_variables.txt
file

Command is :

./mysqlbackup --defaults-file=/etc/my.cnf -p --incremental --start-lsn=1634809 --incremental-backup-


dir=/friday2 backup

./mysqlbackup --defaults-file=/etc/my.cnf -p --incremental --start-lsn=1641233 --incremental-backup-


dir=/staurday backup

Incremental backup Without giving lsn no:

mysqlbackup --defaults-file=/etc/my.cnf -p --incremental --incremental-backup-dir=/backup/friday --


incremental-base=dir:/backup backup

To recover from incremental backups :

Merge all incremental backup directories start from the oldest.in our case /Friday2 is the oldest
incremental backup directory.

./mysqlbackup -u root -p --incremental-backup-dir=/friday2 --backup-dir=/backup apply-incremental-


backup
Then the next incremental backup to be rolled out, in our case it is /Saturday.

./mysqlbackup -u root -p --incremental-backup-dir=/Saturday --backup-dir=/backup apply-incremental-


backup

After that use the same method of recovery which you have used for full backup recovery method.

./mysqlbackup -p copy-back
 #!/bin/bash -x
#Tue Jul 2 15:32:21 CEST 2013
#Made by Edward Z.
set -e #stops execution if a variable is not set
set -u #stop execution if something goes wrong

usage() {
echo "usage: $(basename $0) [option]"
echo "option=full: do a full backup of vinnie /var/lib/mysql using
innobackupex, aprox time 6 hours."
echo "option=incremental: do a incremental backup"
echo "option=restore: this will restore the latest backup to vinnie,
BE CAREFUL!"
echo "option=help: show this help"
}

full_backup() {
date
if [ ! -d $BACKUP_DIR ]
then
echo "ERROR: the folder $BACKUP_DIR does not exists"
exit 1
fi
echo "doing full backup..."
echo "cleaning the backup folder..."
rm -rf $BACKUP_DIR/*
echo "cleaning done!"
innobackupex $ARGS $BACKUP_DIR/FULL
date
echo "backup done!, now uncompressing the files..."
for bf in `find $BACKUP_DIR/FULL -iname "*\.qp"`; do qpress -d $bf $
(dirname $bf) ;echo "processing" $bf; rm $bf; done
date
echo "uncompressing done!, preparing the backup for restore..."
innobackupex --apply-log --redo-only $BACKUP_DIR/FULL
date
echo "preparation done!"
}
incremental_backup()
{
if [ ! -d $BACKUP_DIR/FULL ]
then
echo "ERROR: no full backup has been done before. aborting"
exit -1
fi

#we need the incremental number


if [ ! -f $BACKUP_DIR/last_incremental_number ]; then
NUMBER=1
else
NUMBER=$(($(cat $BACKUP_DIR/last_incremental_number) + 1))
fi
date
echo "doing incremental number $NUMBER"
if [ $NUMBER -eq 1 ]
then
innobackupex $ARGS --incremental $BACKUP_DIR/inc$NUMBER --
incremental-basedir=$BACKUP_DIR/FULL
else
innobackupex $ARGS --incremental $BACKUP_DIR/inc$NUMBER --
incremental-basedir=$BACKUP_DIR/inc$(($NUMBER - 1))
fi
date
echo $NUMBER > $BACKUP_DIR/last_incremental_number
echo "incremental $NUMBER done!, now uncompressing the files..."
for bf in `find $BACKUP_DIR/inc$NUMBER -iname "*\.qp"`; do qpress -d
$bf $(dirname $bf) ;echo "processing" $bf; rm $bf; done
date
echo "uncompressing done!, the preparation will be made when the
restore is needed"

restore()
{
echo "WARNING: are you sure this is what you want to do? (Enter 1 or
2)"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) echo "aborting... that was close."; exit;;
esac
done

echo "cross your fingers :)"


date
echo "doing restore..."
#innobackupex --apply-log --redo-only $BACKUP_DIR/FULL

#we append all the increments


P=1
while [ -d $BACKUP_DIR/inc$P ] && [ -d $BACKUP_DIR/inc$(($P+1)) ]
do
echo "processing incremental $P"
innobackupex --apply-log --redo-only $BACKUP_DIR/FULL --
incremental-dir=$BACKUP_DIR/inc$P
P=$(($P+1))
done

if [ -d $BACKUP_DIR/inc$P ]
then
#the last incremental has to be applied without the redo-only
flag
echo "processing last incremental $P"
innobackupex --apply-log $BACKUP_DIR/FULL --incremental-
dir=$BACKUP_DIR/inc$P
fi

#we prepare the full


innobackupex --apply-log $BACKUP_DIR/FULL
#finally we copy the folder
cp -r $DATA_DIR $DATA_DIR.back
rm -rf $DATA_DIR/*
innobackupex --copy-back $BACKUP_DIR/FULL

chown -R mysql:mysql $DATA_DIR

#######################################
#######################################
#######################################

BACKUP_DIR=/tmp/backup
DATA_DIR=/var/lib/mysql
USER_ARGS=" --user=root --password=password"

ARGS="--rsync $USER_ARGS --no-timestamp --compress --compress-threads=4"

if [ $# -eq 0 ]
then
usage
exit 1
fi

case $1 in
"full")
full_backup
;;
"incremental")
incremental_backup
;;
"restore")
restore
;;
"help")
usage
break
;;
*) echo "invalid option";;
esac

You might also like