Get the App
SLTechnology News&Howtos  ›  Database  › 

Online mysql database backup

Shulou Source: shulou.com Published: 2022-06-01 18:23:36 10月05日 Update

#! / bin/bash

# =

# FileName: MySQLBackup.sh

# Desc: MySQL Databases backup tool.

# Author: chenzm

# Email:969113439@qq.com

# HomePage: http://chenzm0592.blog.51cto.com/

# Version: 0.0.1

# LastChange: 2013-11-15 09:16:39

# History:

# =

Cd / opt/MySQLBackup

. / etc/profile

USERNAME='root'

PASSWORD='password'

U_ID=0

GalliID =

# set mysqldump parameters

MYSQLDUMP= "mysqldump-opt-default-character-set=utf8-skip-lock-tables-C"

# set compression parameters to read from stdin

COMPRESS= "gzip-9"

# set the suffix name of the compressed file, which corresponds to the compression parameter

COMPRESS_EXT= "gz"

DATE=$ (date +% Y-%m-%d)

Mkdir-p logs/

# define log input

Function log () {

# echo-ne ${1}

Echo-ne ${1} > > logs/backup-$ {DATE} .log

}

# minutes and seconds when calculating characters

Function charDate () {

DATE=$1

If [${DATE}-lt 60]; then

Echo "${DATE} seconds"

Elif [${DATE}-ge 60] & & [${DATE}-lt 3600]; then

Echo "$((DATE/60)) minutes $((DATE%60)) seconds"

Else

Masking $((DATE%3600))

Echo "$((DATE/3600)) hour $((M DATE/3600 60)) minutes $((M% 60)) seconds"

Fi

}

TIME_HOST_START=$ (date +% s)

Retry=0

While:

Do

Data=$ (mysql-u$ {USERNAME}-p$ {PASSWORD}-h IP-e 'SHOW DATABASES' 2 > & 1)

If [$? = = 0]; then

Break

Elif [${retry}-ge 5]; then

Log "failed to connect to the database. Exit.\ n"

Exit 1

Fi

((retry++))

Done

DBS=$ (echo ${data} | awk 'BEGIN {split ("test | information_schema", arr, "|"); for (i in arr) b [arr [I]]} END {for

Tags: Parameters data database success in progress backup suffix character hour quantity file log later pipe input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Docker Huawei Shulou Tech Info Xiaomi