How to disable automatic upgrades on Ubuntu 20.04

Home


To backup a MySQL database running inside a Docker container, you can use the mysqldump utility. Here are the steps to create a backup:

Identify the MySQL container's name or ID:

docker ps

Look for the container running MySQL in the output and note its name or ID.

Use mysqldump to create a backup:

docker exec CONTAINER_ID_OR_NAME sh -c 'exec mysqldump --user=YOUR_MYSQL_USERNAME --password=YOUR_MYSQL_PASSWORD --all-databases' > backup.sql

Replace CONTAINER_ID_OR_NAME with the actual container name or ID, and YOUR_MYSQL_USERNAME and YOUR_MYSQL_PASSWORD with your MySQL username and password, respectively. This command will create a file named backup.sql containing the backup of your MySQL databases.

If you want to back up a specific database, replace --all-databases with -B DATABASE_NAME:

docker exec CONTAINER_ID_OR_NAME sh -c 'exec mysqldump --user=YOUR_MYSQL_USERNAME --password=YOUR_MYSQL_PASSWORD -B DATABASE_NAME' > backup.sql

Replace DATABASE_NAME with the name of the database you want to back up.

Secure the backup file:
Make sure to properly secure the backup file by setting the correct permissions and storing it in a safe location.

To restore the database from the backup file, you can use the following command:

docker exec -i CONTAINER_ID_OR_NAME sh -c 'exec mysql --user=YOUR_MYSQL_USERNAME --password=YOUR_MYSQL_PASSWORD' < backup.sql

Again, replace CONTAINER_ID_OR_NAME, YOUR_MYSQL_USERNAME, and YOUR_MYSQL_PASSWORD with the appropriate values. This command will restore the database(s) from the backup.sql file.



Author: Sebastian Emilio Narvaez

Created: 2023-05-23 Tue 00:49

Validate