[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]

Currently, I am outsourcing to help with data collection by scraping using Rails application, but since I am using the Docker environment, it will be difficult if I accidentally delete volume etc. I back up my data every time I finish. (There are about 330,000 records)

I'll show you how to do that!

Backup procedure

Create the file you want to insert the backup data in the Rails root directory and execute the following command.


$ docker exec -it CONTAINER_NAME (eg:myapp_db_1) mysqldump DATABASE_NAME(Example:myapp_development etc.) > backup.sql

Restore (import) procedure

Create the backup file (dump.sql) you want to import in the Rails root directory and execute the following command.


$ docker cp dump.sql mydocker_db_1:/tmp/dump.sql
$ docker exec -it myapp_db_1 bash
$ mysql -u USER_NAME -p -h HOST_NAME(database.yml host name,db) DB_NAME(myapp_development etc.) < /tmp/dump.sql

You can enter the container with docker exec -it myapp_db_1 bash and import it with the mysql command!

In the future, I think it would be even better if data backup could be automated, so I would like to take on the challenge!

that's all!

Thank you for reading!

If you have any suggestions, I would appreciate it if you could comment!

Recommended Posts

[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
[Ruby On Rails] How to search and save the data of the parent table from the child table
[Rails MySQL] How to reset DB on heroku
Ruby on Rails ✕ Docker ✕ MySQL Introducing Docker and docker-compose to apps under development
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
How to run React and Rails on the same server
[Rails] How to speed up docker-compose
[Rails] How to get the URL of the transition source and redirect
How to delete large amounts of data in Rails and concerns
How to change the maximum and maximum number of POST data in Spark
How to solve the local environment construction of Ruby on Rails (MAC)!
[Ruby On Rails] How to search the contents of params using include?
[Ruby on Rails] How to make the link destination part of the specified id
Fat Can, Docker and I look back on the quotes of First Gundam
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
Run Docker environment Rails MySQL on Heroku. devise and hiding the twitter API
How to make a unique combination of data in the rails intermediate table
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
Docker the development environment of Ruby on Rails project
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Ruby on Rails] How to change the column name
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails] How to delete production environment MySQL data after putting it in the development environment
[Rails] How to change the column name of the table
[Ruby On Rails] How to reset DB in Heroku
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
[Rails] How to get the contents of strong parameters
Install MySQL 5.6 on CentOS6 [How to specify the version]
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
(Ruby on Rails6) How to create models and tables
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
How to mark up search keywords regardless of case and without changing the search source word
Install docker and docker-compose on ubuntu in the shortest process
[With back tricks] How to introduce React to the simplest Rails
Let's summarize how to extend the expiration date of Rails
[Rails] How to display the list of posts by category
When you want to change the MySQL password of docker-compose
How to check the extension and size of uploaded files
How to deploy a Rails application on AWS (article summary)
How to check the database of apps deployed on Heroku
Procedure for migrating Rails application development environment to Docker even if you are inexperienced (Rails5 + MySQL8.0 + docker-compose)
How to make an application with ruby on rails (assuming that the environment has been built)
How to build an environment with Docker, which is the minimum required to start a Rails application
How to pick up the input value by asynchronous communication and output the desired data from the server
Method definition location Summary of how to check When defined in the project and Rails / Gem
Read the data of Shizuoka point cloud DB with Java and try to detect the tree height.
[Swift] How to dynamically change the height of the toolbar on the keyboard
[Docker-compose] How to use unnamed and named volumes of volumes. Bind mount
[Swift5] How to get an array and the complement of arrays
How to set the IP address and host name of CentOS8
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
How to display 0 on the left side of the standard input value
[Rails] How to introduce kaminari with Slim and change the design
How to install and configure the monitoring tool "Graphite" on Ubuntu
[Swift UI] How to get the startup status of the application [iOS]