Home > bash, Linux, MySQL, OpenStack, RHEL > Daily backup OpenStack single MySQL with Percona innobackupex including the /etc directory

Daily backup OpenStack single MySQL with Percona innobackupex including the /etc directory

this is a short script for daily backup of the OpenStack MySQL and the /etc direcotry of the control node

[root@dev-epg-rhos-01 BACKUP]# cat /root/bin/epg.innobackupex.openstack.sh
#!/bin/sh
# done for epgmad4@tid.es
# Barcelona Thu Oct 17 16:30:36 CEST 2013

days_to_keep=7
NFS=/BACKUP
exportDate=`date +%Y-%m-%d.%H.%M.%S`
export_DIR=${NFS}/${HOSTNAME}.${exportDate}
test ! -d "${export_DIR}" && echo "$(date) : creating ${export_DIR}" && mkdir -p "${export_DIR}"
export_MySQL_DIR=${export_DIR}/mysql.bckp
export_ETC_DIR=${export_DIR}/etc.bckp
rsync -avh /etc ${export_ETC_DIR}
echo "=========================================================================================================" >> ${export_DIR}/README.restore.with.innobackupex
echo "HOW to restore this FULL mysql backup" >> ${export_DIR}/README.restore.with.innobackupex
echo "=========================================================================================================" >> ${export_DIR}/README.restore.with.innobackupex
echo "DO IT IN A SCREEN, as it involves some file movements:" >> ${export_DIR}/README.restore.with.innobackupex
echo "screen -S mysqlRestore" >> ${export_DIR}/README.restore.with.innobackupex
echo "service stop mysql" >> ${export_DIR}/README.restore.with.innobackupex
echo "ps aux | grep mysql" >> ${export_DIR}/README.restore.with.innobackupex
echo "rsync -avh /var/lib/mysql /var/lib/mysql.BAD" >> ${export_DIR}/README.restore.with.innobackupex
echo "rm -rf /var/lib/mysql" >>  ${export_DIR}/README.restore.with.innobackupex
echo "mkdir -p /var/lib/mysql && chown -R mysql:mysql /var/lib/mysql" >>  ${export_DIR}/README.restore.with.innobackupex
echo "innobackupex --copy-back ${export_MySQL_DIR}" >>  ${export_DIR}/README.restore.with.innobackupex
echo "=========================================================================================================" >> ${export_DIR}/README.restore.with.innobackupex
echo "more info at http://www.percona.com/doc/percona-xtrabackup/2.1/innobackupex/restoring_a_backup_ibk.html:" >>  ${export_DIR}/README.restore.with.innobackupex
cat /root/bin/README.restore.with.innobackupex >> ${export_DIR}/README.restore.with.innobackupex
innobackupex --ibbackup=xtrabackup --no-timestamp ${export_MySQL_DIR}
test $? -gt 0 && echo "$(date) : xtrabackup failed at ${export_MySQL_DIR}" && exit 0
innobackupex --apply-log ${export_MySQL_DIR}
find ${NFS}/ -daystart -maxdepth 1 -ctime +${days_to_keep} -type d -name "*${HOSTNAME}*" -exec /bin/rm -rf {} \;

#Slackware4Life!

the README.restore.with.innobackupex content:

cat /root/bin/README.restore.with.innobackupex
Restoring a Full Backup with innobackupex
For convenience, innobackupex has a –copy-back option,
which performs the restoration of a backup to the server’s datadir

$ innobackupex –copy-back /path/to/BACKUP-DIR
It will copy all the data-related files back to the server’s datadir,
determined by the server’s my.cnf configuration file.
You should check the last line of the output for a success message:
==================================================
=> innobackupex: Finished copying back files. <=
=> 111225 01:08:13 innobackupex: completed OK! <=
==================================================

Note The datadir must be empty; Percona XtraBackup innobackupex –copy-back option will not copy over existing files.
Also it’s important to note that MySQL server needs to be shut down before restore is performed.
You can’t restore to a datadir of a running mysqld instance (except when importing a partial backup).
As files’ attributes will be preserved, in most cases you will need to change the files’ ownership
to mysql before starting the database server, as they will be owned by the user who created the backup:

$ chown -R mysql:mysql /var/lib/mysql
Also note that all of these operations will be done as the user calling innobackupex,
you will need write permissions on the server’s datadir.

About these ads
  1. September 8, 2014 at 7:39 am

    Reblogged this on minhhanbe.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: