当前位置:网站首页>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
边栏推荐
- 上一次听到易趣,还是上一次
- 周伟:寻找非共识性投资机会,陪伴延迟满足的创始团队
- 消息的订阅和发布
- B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
- Sword finger offer (VII): Fibonacci sequence
- Sword finger offer (x): rectangular coverage
- JSON data returned by controller
- Canvas upload image Base64 with cropping function jcrop.js
- Upload pictures to get width and height
- 估值15亿美元的独角兽被爆裁员,又一赛道遇冷?
猜你喜欢

Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase

Photoshop(CC2020)未完

Videojs to canvas pause, play, switch video
Exploration on cache design optimization of community like business

Uncover the secret of white hat: 100 billion black products on the Internet scare musk away
![[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]](/img/f3/48ca9e1e8889afc0993084d6416575.png)
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]

WPS凭什么拒绝广告?

重押海外:阿里、京东、顺丰再拼“内力”

See you tomorrow at the industrial session of cloud intelligence technology forum!

How to write the introduction of GIS method journals and papers?
随机推荐
【开源之美】nanomsg(2) :req/rep 模式
《Kotlin系列》之MVVM架构封装(kotlin+mvvm)
数据泄漏、删除事件频发,企业应如何构建安全防线?
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
Convert the array in JSON file to struct
Familiarize you with the "phone book" of cloud network: DNS
【C语言学习者必会的题目集锦1】巩固基础,稳步提高
SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
Videojs to canvas pause, play, switch video
历时15年、拥有5亿用户的飞信,彻底死了
JUC summary
How to write the introduction of GIS method journals and papers?
Activity.onStop() 延迟10秒?精彩绝伦的排查历程
B+ tree selection index (1) -- MySQL from entry to proficiency (22)
Pytoch learning notes (II) the use of neural networks
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
Win11+VS2019配置YOLOX
Sword finger offer (x): rectangular coverage
The.Net webapi uses groupname to group controllers to render the swagger UI
详解关系抽取模型 CasRel