====== Migrating MariaDB Database from LXC to Docker ======
===== Steps =====
==== 1. Backup the Database from LXC Instance ====
* 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
* This command creates a backup file named ''veeamreports.bak'' in the current directory.
==== 2. Copy the Backup to Docker Host ====
* 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 facundo@racknerd-vpn.facundoitest.space:/home/facundo/sql-migration/
* 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 ====
* 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
* 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 ====
* 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
* **Permissions**: Ensure ''facundo'' has the necessary permissions on both the source and destination databases.
* **Container Access**: If ''mariadb'' is not recognized, try ''mysql'' or confirm the correct executable name for MariaDB in your setup.