Database backup Sunday full + daily incremental backup script using Xtrabackup

Source: Internet
Author: User

I believe that many of the small partners will use the MySQL database, the following provides a script to share with gentlemen.


#!/bin/bash
script_dir=$ (dirname)
Backup_dir= "/data1/mysqlbackup"
backup_days=480
RM-RF ${backup_dir}/*
db_ip= '/sbin/ifconfig-a|grep inet|grep-v 127.0.0.1|grep-v Inet6|awk ' {print $} ' |tr-d ' addr: ' |head-1 '
Backup_type= ' Xtra_full '
For i in ' Ps-ef |grep port= |grep-v grep|cut-d "="-F 10 '
Do
db_port= $i
New_dir= "/data1/mysqlbackup/${db_port}"
If [-E "$NEW _dir"]
Then
echo "$NEW _dir was created"
Else
mkdir $NEW _dir
Fi
backup_today= "/data1/mysqlbackup/${db_port}/${db_ip}_ ' Date +%y%m%d%h%m '"

#find ${backup_dir}-mindepth 2-type d-cmin +${backup_days}-exec rm-rf {} \;

/usr/bin/mysql-h127.0.0.1-p${db_port}-uroot-e "GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT on * * to ' mysqlbackup ' @12 7.0.0.1 identified by ' abc123 ' "
/usr/bin/mysql-h127.0.0.1-p${db_port}-uroot-e "Grant replication Slave on * * to [email protected] ' 10.37.53.% ' IdentiFi Ed by ' Password '
/usr/bin/mysql-h127.0.0.1-p${db_port}-uroot-e "Grant all on * * to [e-mail protected] ' 10.37.53.% ' identified by ' password '
/usr/bin/mysql-h127.0.0.1-p${db_port}-uroot-e "Grant all on * * to [e-mail protected] ' 127.0.0.1 ' identified by ' password '

Innobackupex--user=mysqlbackup--password=abc123--host=127.0.0.1--port=${db_port}--defaults-file=/etc/mysql/my$ {db_port}.cnf--no-timestamp $BACKUP _today 2>/var/log/mysql${db_port}.log


This article from "Snail Taunt" blog, reproduced please contact the author!

Use Xtrabackup for database backup Sunday full + daily Incremental backup script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.