Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Database backup Sunday full + Daily incremental backup script

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I believe that many small partners who do operation and maintenance will use the mysql database. Here is a script to share with you.

#! / bin/bash

SCRIPT_DIR=$ (dirname $0)

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 $2}'| 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-h227.0.0.1-P$ {DB_PORT}-uroot-e "GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *. * TO 'mysqlbackup'@127.0.0.1 IDENTIFIED BY' abc123'"

/ usr/bin/mysql-h227.0.0.1-P$ {DB_PORT}-uroot-e "grant replication slave on *. * to replica@'10.37.53.%' identified by 'password'"

/ usr/bin/mysql-h227.0.0.1-P$ {DB_PORT}-uroot-e "grant all on *. * to mha_user@'10.37.53.%' identified by 'password'"

/ usr/bin/mysql-h227.0.0.1-P$ {DB_PORT}-uroot-e "grant all on *. * to zabbix_monitor@'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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report