Started by Allen ScottOct 31, 2021

Closed
How to recover mysql data files from docker containers

3 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 3 VIEWES SHARE

The man who putting in place snipe/snipe-it changed into leaving from our organisation couple months in the past. He mounted that snipe/snipe-it with docker and located that server (ec2 instance) turned into crashed and can't get better anymore as now not starting off anymore. It's why I have created another ec2 instance and copied all of documents inner old ec2 example to new ec2 instance. Now, I'm suffering that how may want to I get better mysql statistics inner docker in old ec2 example volume.

I found that some folders (as docker containers) inside var/lib/docker/overlay2/ but I have not found mysql data file inside there. Please let me know how to recover it.

2 Replies

Murray Thomson replied a day ago0 likes0 dislikes

First, get the list of dangling volumes.

$ docker volume ls -f dangling=true
DRIVER              VOLUME NAME
local               6f79b6329d98379495a284287e32a7a57605483dd7bf7fa19924fb2a98fb1d19
local               47bb077ef6f6df9f56bd30c35eeb45f35e62213d2c50db6f078bfdeeee6698ec

Then mounted it into a Ubuntu container

$ docker run --name tempContainer1-UBUNTU -v 6f79b6329d98379495a284287e32a7a57605483dd7bf7fa19924fb2a98fb1d19:/var/lib/backup -t -i ubuntu /bin/bash

Then you will be inside the bash of a newly created contianer. Go to the newly mounted directory and check the content

$cd /var/lib/backup
$ls
$aria_log.00000001  aria_log_control  ib_buffer_pool  ib_logfile0  ib_logfile1  ibdata1  ibtmp1  multi-master.info  mysql  performance_schema
-- once you are sure directory data is what you require, make a zip file of the folder 
$apt-get update
$apt-get install zip
$cd ..
$zip -r backup.zip backup

On another terminal from the host copy the content of container backup.zip to host

$docker cp tempContainer1-UBUNTU:/var/lib/backup.zip.

Then create a docker-compose file like the following and mount the backup folder as a data directory. Run this on Linux host as this mounting will not work as expected for MySQL on windows.

version: "3.2"
services:
  mysql:
    image: mariadb:10.4.12
    restart: always
    ports:
      - "3306:3306"      
    command: mysqld --innodb-flush-method=littlesync --innodb-use-native-aio=ON --log_bin=ON
    volumes:
            - ./backup_data_folder:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: somepassword
      TZ: Asia/Singapore
    networks:
      - frontend
    container_name: maria
networks:
  frontend:

Start

$docker-compose up

Once it is up, from another terminal go inside the newly created container

$docker exec -t -i maria /bin/bash
-- Take dump of all the DBS 
$mysqldump -u root -p --all-databases > alldb.sql

Copy content of the dump to host from another terminal from the host

$docker cp maria:/alldb.sql.

Now, this SQL file is a full dump, restore it as usual on your MySQL DB or contianer.

MySQL -u root -p < alldb.sql 
Allen Scott replied a day ago0 likes0 dislikes

Thanks for ur replyđź‘Ť

This thread is closed by Abhishek
Trending Categories
15
Software39
DevOps45
Frontend Development24
Backend Development18
Server Administration17
Linux Administration24
Data Center24
Sentry24
Terraform21
Ansible29
Docker28
Penetration Testing14
Kubernetes16
NGINX19
JenkinsX17
Techiio

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

facebooklinkdeintwitter

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Copyright techiio.com @2020 Kolkata, India
made with by Abhishek & Priyanka Jalan
Copyright techiio.com @2020
made with by Abhishek & Priyanka Jalan