当前位置:网站首页>[docker]mysql scheduled backup
[docker]mysql scheduled backup
2022-06-10 00:23:00 【Djc8 small yard farmer】
Preface
Today, I adjusted the parameters of the machine , Make a backup , I think I haven't done automatic backup yet , If the data is lost , There's nothing left . So I studied , Use mysqldump To schedule backups mysql The data of .
analysis
My database runs in a container , Cannot run directly on the host mysqldump Command backup ( The host does not care about the database instance type , And will not install these things ), If you want to back up, you need to use docker exec Enter the container for backup , This obviously provides us with an idea . I now need to mount a path to the container mysql example , So that the container can store the backed up files directly . Then you need to write a crontab Automated task scripts .
Container mount Directory
Because when containers are used , Adopt the principle of least modification , Try not to automatically generate the configuration of the moving capacitor , So I'm going to stop the container here , And remove . The container performs a stop operation first docker stop mysql. Container removal docker rm mysql'. Add mount directory -v /bak/mysqlbak/:/tmp/mysqlbak` For example, the following script
sudo docker run \
--network=djc8net --name mysql \
-v /database/data/:/var/lib/mysql \
-v /database/mysql/conf:/etc/mysql/conf.d \
-v /bak/mysqlbak/:/tmp/mysqlbak \
-e MYSQL_ROOT_PASSWORD=test \
-d mysql:8.0.22After the operation is completed , You can see in the container that it contains /tmp/mysqlbak Catalog , This directory is the path where we need to store the backup .
Backup scripts
Use mysqldump The data can be flexibly backed up as sql Script , Easy to distribute . First create a sh file :touch /tool/autojob/bak_mysql.sh The contents are as follows :
#!/bin/bash
export NOW="$(date +"%Y-%m-%d")"
export DATA_DIR=/tmp/mysqlbak
docker exec -it mysql /bin/bash -c "mysqldump -uroot -ptest --set-gtid-purged=OFF --all-databases > $DATA_DIR/$NOW.sql"I back up all the databases here .
Grant authority :chmod +x /tool/autojob/bak_mysql.sh Debugging operation :./tool/autojob/./bak_mysql.sh If there is no problem, check /bak/mysqlbak You will see a with the current date as the name sql The script .
Automatically run backup scripts
perform :crontab -e. Add a line at the bottom :20 01 * * * /tool/autojob/bak_mysql.sh preservation , And perform :crontab -l. This line will appear in the list . The backup time is every morning 01 spot 20 branch .
边栏推荐
- Where is the bookmark saved in Google browser and how to import and export bookmarks
- How can C get entity class attribute names and values?
- BP neural network inversion of water quality parameters based on MATLAB
- On chip variation (OCV) concept learning
- 彭博终端产品覆盖的加密资产数量扩大为前50名资产
- MySQL transaction
- C#实用技巧之:将图标打包进DLL并读取
- With the advent of the digital era, 360 has joined hands with the dark horse of entrepreneurship to help small and medium-sized enterprises seize the key future
- 银行有没有必要建立数据中台?看完你就明白了
- ArcMap解决几何错误
猜你喜欢

Mind map - 3. SQL injection vulnerability

慢查询如何优化?(实战慢查询)

IOS cache - nscache and sandbox cache

The cornerstone mvcc mechanism of repeatable read isolation level

哨兵3(Sentinel-3)数据简介

With the advent of the digital era, 360 has joined hands with the dark horse of entrepreneurship to help small and medium-sized enterprises seize the key future

MySQL执行计划

PMP high frequency knowledge sorting

Py6S配置教程(win10 ×64)

我服了,MySQL表500W行,居然有人不做分区?
随机推荐
请教一个问题,pg有类似mysql server_id一样的实例唯一标识么?
Numpy basic operation
哨兵3(Sentinel-3)数据简介
Les contrats à terme Huishang sont - ils formels? La transaction d'ouverture de compte est - elle sécurisée?
没有项目管理经验,可以参加PMP考试?
Py6S配置教程(win10 ×64)
C # WPF realizes dynamic increase and decrease of tab page
10个常见触发IO瓶颈的高频业务场景
Blue Bridge Cup_ Split cube_ Combinatorial mathematics_ Addition principle
Dynamic reading of protobuf data
电脑连接打印机出现的问题(打印机显示未指定)解决方法
The number of encrypted assets covered by Bloomberg terminal products expanded to the top 50 assets
辐射亮度与表观反射率的转换
Ups and downs of network status
Enterprise worry free | apipost privatization deployment activity is about to start
SPSS principal component analysis
C# WPF 实现Tab页动态增减
“当你不再是程序员,很多事会脱离掌控”—— 对话全球最大独立开源公司SUSE CTO
The cornerstone mvcc mechanism of repeatable read isolation level
Virtual machine environment configuration record 1