Docker MySQL Backup

Source: Internet
Author: User
Tags db2 mysql backup docker run


Creating a backup MySQL container

Docker run--name mysql-back-e mysql_root_password=root-v/srv/mysql/backup:/mysql/backup-d mysql:5.7.17

View virtual networks, where bridge is the virtual network that Docker uses by default:

Docker Network Inspect Bridge

  

In the returned results, locate the Containers section. The contents are as follows:

"Containers": {  "asdf2334a": {"    Name": "Mysql-a"    "EndpointId": "sadfas234"    "MacAddress": "...."    "ipv4address": "192.168.0.2"    "ipv6address": ""  }}

Containers lists all the containers that use the bridge network. Because I named the MySQL server container as mysql-a, I looked at the configuration of name Mysql-a. IPv4Address indicates that the virtual IP of the container mysql-a is 192.168.0.2. Record this IP.

Bash into the container:

Docker exec-it Mysql-b Bash

Install Vim and cron timed tasks:

Apt-get Update && apt-get install vimapt-get update && apt-get install cron

Generate a shell script file to be backed up.

Cat >/zc/mysql/backup.sh <<eof#!/bin/shzcdate=\$ (date +%y%m%d) mkdir/zc/mysql/backup/\ $zcDATEmysqldump-H ' 192.168.0.2 '-uroot-p ' 123456 '--databases db1 >/zc/mysql/backup/\ $zcDATE/db1.sqlmysqldump-h ' 192.168.0.2 '-uroot- P ' 123456 '--databases DB2 >/zc/mysql/backup/\ $zcDATE/db2.sqleof

There are two databases on MySQL, named DB1 and DB2, which use this method to back up data on the hard disk. -H indicates the remote server IP. -U and-P are the user names and passwords for the remote server, respectively. It is not recommended to use the –all-database option for mysqldump. Because this option will also back up the system database in remote MySQL, including the root user's password and so on. If you want to import the exported content to another machine, these system settings (such as user name and password) will overwrite the original settings on your machine.

To set the start time for a scheduled task:

CRONTAB-E0 * * * sh/zc/mysql/backup.sh

Start a scheduled task

Service Cron Start

  

Docker MySQL Backup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.