Docker Backup and restore question

Hi
I was wondering if someone could shed some light on the issue im having,

Currently trying to backup my docker-compose wordpress from one host and trying to migrate to another host
But im having difficulty understanding the restore process

This is my docker compose

version: '3.9'

services:
  # Database
  db:
    image: mysql:8.0
    volumes:
      - /wordpress/db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: mypassword
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: mypassword
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8083:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: mypassword
    networks:
      - wpsite
  # Wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8084:80'
    restart: always
    volumes:
      - /wordpress/html:/var/www/html
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: mypassword
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:
  html:

on host1 i ran

 docker run --rm --volumes-from deepsight_wordpress_1 -v $(pwd):/backup busybox tar cvfz /backup/wordpress.tar /var/www/html

 docker run --rm --volumes-from deepsight_db_1 -v $(pwd):/backup busybox tar cvfz /backup/db.tar /var/lib/mysql

then i sftp copied the db.tar and the wordpress.tar to the other hosts

but on host2 when i try to restore, i get this error, my question is where would i place the tar files on the host2? for the restore which i think that might be the issue


docker run --rm --volumes-from deepsight-wordpress-1 -v $(pwd):/backup busybox bash -c "cd /var/www/html && tar xvf /backup/wordpress.tar --strip 1"
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "bash": executable file not found in $PATH: unknown.

Thank you

Assumed the volume deepsight-wordress-1 exists,try:

docker run --rm --volumes-from deepsight-wordpress-1 -v $(pwd):/backup busybox tar xvf /backup/wordpress.tar --strip 1 -C /var/www/html 

The error message says that bash can not be found. The busybox images has sh, but no bash command. Though, in your case you don’t realy need it.

Note: depending on the application, creating a backup from a running container’s volume can lead to inconsistent backups.

Thank you so much for the reply, the first command worked perfectly, now im trying to restore the docker container db but im getting this

docker run --rm --volumes-from deepsight-db-1 -v $(pwd):/backup busybox tar xvf /backup/db.tar --strip 1 -C /var/lib/mysql
tar: invalid tar header checksum

If you use cvzf while creating the archive, you need to use xvzf to extract the archive (the v is optional in both). The z indicates wether the tar archive is gzip`ed.

Note: you can not create a consistent copy of the mysql volume when the container is running.

Thanks you so much for the reply, you were right adding that command i was able to restore, i did restore it when the container was turned off but now im getting this error :smiling_face_with_tear:

2022-07-12T21:00:07.625446Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:07.626328Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:07.626593Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:07.628919Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.
2022-07-12 21:00:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-12 21:00:09+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-12 21:00:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-07-12T21:00:10.998124Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-12T21:00:11.026493Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-12T21:00:11.083839Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2022-07-12T21:00:11.084105Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 1 = ['lib/mysql/sys/sys_config.ibd', 'sys/sys_config.ibd'] 
2022-07-12T21:00:11.084215Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967278 = ['lib/mysql/undo_002', 'undo_002'] 
2022-07-12T21:00:11.084316Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967279 = ['lib/mysql/undo_001', 'undo_001'] 
2022-07-12T21:00:11.084387Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967294 = ['lib/mysql/mysql.ibd', 'mysql.ibd'] 
2022-07-12T21:00:11.084516Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2022-07-12T21:00:11.084699Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:11.085127Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:11.085575Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:11.087329Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.
2022-07-12 21:00:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-12 21:00:13+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-12 21:00:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-07-12T21:00:14.632313Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-12T21:00:14.660671Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-12T21:00:14.725685Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2022-07-12T21:00:14.726220Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 1 = ['lib/mysql/sys/sys_config.ibd', 'sys/sys_config.ibd'] 
2022-07-12T21:00:14.726751Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967278 = ['lib/mysql/undo_002', 'undo_002'] 
2022-07-12T21:00:14.726865Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967279 = ['lib/mysql/undo_001', 'undo_001'] 
2022-07-12T21:00:14.726979Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967294 = ['lib/mysql/mysql.ibd', 'mysql.ibd'] 
2022-07-12T21:00:14.727111Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2022-07-12T21:00:14.727281Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:14.727708Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:14.727991Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:14.729382Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.
2022-07-12 21:00:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-12 21:00:19+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-12 21:00:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-07-12T21:00:20.743709Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-12T21:00:20.766620Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-12T21:00:20.809700Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2022-07-12T21:00:20.809916Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 1 = ['lib/mysql/sys/sys_config.ibd', 'sys/sys_config.ibd'] 
2022-07-12T21:00:20.810113Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967278 = ['lib/mysql/undo_002', 'undo_002'] 
2022-07-12T21:00:20.810234Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967279 = ['lib/mysql/undo_001', 'undo_001'] 
2022-07-12T21:00:20.810285Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967294 = ['lib/mysql/mysql.ibd', 'mysql.ibd'] 
2022-07-12T21:00:20.810374Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2022-07-12T21:00:20.810545Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:20.810839Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:20.811133Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:20.812282Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.
2022-07-12 21:00:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-12 21:00:24+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-12 21:00:24+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-07-12T21:00:24.913782Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-12T21:00:24.933022Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-12T21:00:24.959148Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2022-07-12T21:00:24.959299Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 1 = ['lib/mysql/sys/sys_config.ibd', 'sys/sys_config.ibd'] 
2022-07-12T21:00:24.959399Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967278 = ['lib/mysql/undo_002', 'undo_002'] 
2022-07-12T21:00:24.959565Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967279 = ['lib/mysql/undo_001', 'undo_001'] 
2022-07-12T21:00:24.959659Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967294 = ['lib/mysql/mysql.ibd', 'mysql.ibd'] 
2022-07-12T21:00:24.959764Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2022-07-12T21:00:24.959992Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:24.960499Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:24.960853Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:24.961720Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.
2022-07-12 21:00:29+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-12 21:00:29+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-12 21:00:29+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-07-12T21:00:30.869503Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-12T21:00:30.896399Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-12T21:00:30.948892Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2022-07-12T21:00:30.949063Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 1 = ['lib/mysql/sys/sys_config.ibd', 'sys/sys_config.ibd'] 
2022-07-12T21:00:30.949206Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967278 = ['lib/mysql/undo_002', 'undo_002'] 
2022-07-12T21:00:30.949329Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967279 = ['lib/mysql/undo_001', 'undo_001'] 
2022-07-12T21:00:30.949442Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967294 = ['lib/mysql/mysql.ibd', 'mysql.ibd'] 
2022-07-12T21:00:30.949516Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2022-07-12T21:00:30.949678Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:30.950639Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:30.950963Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:30.952238Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.
2022-07-12 21:00:35+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
2022-07-12 21:00:36+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-07-12 21:00:36+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.29-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-07-12T21:00:37.090427Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.29) starting as process 1
2022-07-12T21:00:37.118010Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-07-12T21:00:37.158980Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2022-07-12T21:00:37.159165Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 1 = ['lib/mysql/sys/sys_config.ibd', 'sys/sys_config.ibd'] 
2022-07-12T21:00:37.159239Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967278 = ['lib/mysql/undo_002', 'undo_002'] 
2022-07-12T21:00:37.159290Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967279 = ['lib/mysql/undo_001', 'undo_001'] 
2022-07-12T21:00:37.159354Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 4294967294 = ['lib/mysql/mysql.ibd', 'mysql.ibd'] 
2022-07-12T21:00:37.159429Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2022-07-12T21:00:37.159546Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2022-07-12T21:00:37.160276Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2022-07-12T21:00:37.160621Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-07-12T21:00:37.162362Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.29)  MySQL Community Server - GPL.

I think it might be because i created first the db container stopped it and restore it not sure whats the correct method?

I understood you first started the mysql container with the volume, which created a database and then your restored the tar into the volume where already a dabase exist. My lack of imagination says this can’t be a clean restore.

You first need to create the empty volume, restore the tar into the volume using a temporary container and then start the final mysql container using the volume.

1 Like

There is a much easier way to do this. See the docker-compose file used here:

It includes a script to dump the database to an SQL file (I run the script frequently when working on a site). You can bring the whole thing down, and the next time you start it up, it will load the most recent dump. All you have to move is the folder containing the files, the data dumps, the docker-compose.yaml, the .env file and the data export script. Zip up the folder and move it at will.

In fact I keep those folders in Dropbox, and I can bring the site up on any machine with the Dropbox and docker: Windows, Mac, or Linux.

thank you so much for the reply, in case only applies to wordpress, im looking on a way to have a standard to backup containers and restoring in general