当前位置:网站首页>Docker container MySQL enables binlog and scheduled backup
Docker container MySQL enables binlog and scheduled backup
2022-07-26 13:43:00 【CS beat you】
In order to ensure mysql Data integrity of database , In addition to the database data linked to the host for persistence , Still need to be done binlog And regularly backup data

1, add to mysql Files mapped to docker-stack In file
# Specify on binlog Configuration file for
- /home/test/binlog/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
# Specify the scheduled task execution of the backup database shell file
- /home/test/binlog/mysql-dump.sh:/home/app/mysql-dump.sh
# Specify scheduled backup to store files
- /home/test/binlog/mysql_dump_file:/home/app/sql_backupmysqld.cnf The configuration file is as follows : On is specified binlog And storage binlog Path to file ( This path needs to be attached to the host )
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# To configure binlog Log path of
log-bin=/var/lib/mysql/mysql-bin
# To configure serverid
server-id=123456
mysql-dump.sh The contents are as follows : Scheduled backup mysql Database to /home/app/sql_backup.
#!/bin/bash
# Set up mysql Login username and password for ( Fill in... According to the actual situation )
mysql_user="root"
mysql_password="123456"
mysql_host="localhost"
mysql_port="3306"
mysql_charset="utf8mb4"
# Database name
mysql_backup_database="test"
# Backup file storage address ( Fill in... According to the actual situation )
backup_location=/home/app/sql_backup
# Delete expired data
expire_backup_delete="ON"
# How many days of data are saved
expire_days=15
backup_time=`date +%Y%m%d%H%M`
backup_dir=$backup_location
welcome_msg="Welcome to use MySQL backup tools!"
# Judge mysql Whether the instance is running normally
mysql_ps=`ps -ef |grep mysql |wc -l`
mysql_listen=`netstat -an |grep LISTEN |grep $mysql_port|wc -l`
if [ [$mysql_ps == 0] -o [$mysql_listen == 0] ]; then
echo "ERROR:MySQL is not running! backup stop!"
exit
else
echo $welcome_msg
fi
# Back up the data in the specified database ( Let's assume that the database is mysql_backup_test)
mysqldump -h$mysql_host -P$mysql_port -u$mysql_user -p$mysql_password -B $mysql_backup_database> $backup_dir/mysql_backup_test-$backup_time.sql
flag=`echo $?`
if [ $flag == "0" ];then
echo "database mysql_backup_test success backup to $backup_dir/mysql_backup_test-$backup_time.sql.gz"
else
echo "database mysql_backup_test backup fail!"
fi
# Delete expired data
if [ "$expire_backup_delete" == "ON" -a "$backup_location" != "" ];then
`find $backup_location/ -type f -mtime +$expire_days | xargs rm -rf`
echo "Expired backup data delete complete!"
fi2, After starting the project, enter mysql In container :
- Execute command update linux library : apt-get update
- Install the scheduled task tool : apt-get install -y cron vim
- Edit the task by command : crontab -e
- Add the task command : 59 23 * * * /bin/sh /home/app/mysql-dump.sh
- start-up crontab :service cron start
Here we are ,docker Containers mysql Turn on binlog And scheduled backup processing
边栏推荐
- Analysis on the current situation and optimization strategy of customer experience management in banking industry
- 冒泡排序的时间复杂度分析
- 重押海外:阿里、京东、顺丰再拼“内力”
- [shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
- [oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
- Ultimate doll 2.0 | cloud native delivery package
- Leetcode 2119. number reversed twice
- Sword finger offer (IX): abnormal jumping steps
- Photoshop(CC2020)未完
- 向路由组件传递参数
猜你喜欢

Seven steps to copywriting script ---- document team collaborative management
![[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer](/img/7e/4f652c4d3d72ad563ddbc1c1f1f50b.png)
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer

How to build a customer-centric product blueprint: suggestions from the chief technology officer

Solve the problem that the remote host cannot connect to the MySQL database

终极套娃 2.0 | 云原生交付的封装

In 2022, we "sent away" so many Internet products in only one month

如何构建以客户为中心的产品蓝图:来自首席技术官的建议
![[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light](/img/99/6581b8a576e59a13aa4e977e3a1b70.jpg)
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light

Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation

Pytoch learning notes (I) installation and use of common functions
随机推荐
Photoshop (cc2020) unfinished
【Oauth2】七、微信OAuth2授权登录
Uncover the secret of white hat: 100 billion black products on the Internet scare musk away
I. creation and constraint of MySQL table
【黑马早报】字节旗下多款APP下架;三只松鼠脱氧剂泄露致孕妇误食;CBA公司向B站索赔4.06亿;马斯克否认与谷歌创始人妻子有婚外情...
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
POM文件详解
估值15亿美元的独角兽被爆裁员,又一赛道遇冷?
SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
Click El dropdown item/@click.native
Solution 5g technology helps build smart Parks
MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
Pytoch learning notes (II) the use of neural networks
Propagation of transactions
The use of asynchronous thread pool in development
421. 数组中两个数的最大异或值
Comparison between SIGMOD function and softmax function
Sword finger offer (VII): Fibonacci sequence
Frisbee, 2022 "black red" top stream
We were tossed all night by a Kong performance bug