migrating_mariadb_database_from_lxc_to_docker

This is an old revision of the document!


Migrating MariaDB Database from LXC to Docker

Steps

1. Backup the Database from LXC Instance

  1. Connect to the LXC instance running MariaDB (in this example, api.facundoitest.space) and create a backup using mysqldump. Replace facundo with your username and VeeamReports with your database name:
mysqldump -u facundo -p VeeamReports > veeamreports.bak
  1. This command creates a backup file named veeamreports.bak in the current directory.

2. Copy the Backup to Docker Host

  1. From your local machine or the LXC instance, use scp to transfer the backup file to the Docker host (e.g., racknerd-vpn.facundoitest.space):
scp ./veeamreports.bak [email protected]:/home/facundo/sql-migration/
  1. This will place the file in /home/facundo/sql-migration/ on the Docker host.

3. Ensure Backup File Availability in Docker Container

  • First, enter the Docker container to confirm the backup file’s location:
docker exec -it mariadb /bin/bash

Alternative Methods:

  • Copy the File Directly into the Container:
docker cp /home/facundo/sql-migration/veeamreports.bak mariadb:/veeamreports.bak
  • Mount the Directory During Container Startup (to persist the folder as /backup in the container):
docker run -d --name mariadb -v /home/facundo/sql-migration:/backup mariadb

4. Import the Backup File to MariaDB in Docker

  1. With the backup file accessible in the container, import it into the MariaDB instance by connecting to the container:
docker exec -it mariadb /bin/bash
  1. Run the following command to import the database. VeeamReports is the database name and facundo the user:
mariadb -u facundo -p VeeamReports < veeamreports.bak

5. Verify the Import

  1. Confirm that the database imported successfully by connecting to MariaDB and checking for tables in VeeamReports:
mariadb -u facundo -p
SHOW TABLES IN VeeamReports;

Notes

  1. Permissions: Ensure facundo has the necessary permissions on both the source and destination databases.
  2. Container Access: If mariadb is not recognized, try mysql or confirm the correct executable name for MariaDB in your setup.
migrating_mariadb_database_from_lxc_to_docker.1730522007.txt.gz · Last modified: 2024/11/02 04:33 by oso