fradelg / docker-mysql-cron-backup

Docker image to backup all your databases periodically
Apache License 2.0
305 stars 111 forks source link

Restore path #45

Closed steakhutzeee closed 3 years ago

steakhutzeee commented 3 years ago

Hi,

would like to ask how the restore process works. The databases will be restored in the original paths, picked up from the databases docker compose files?

Thanks!

fradelg commented 3 years ago

You have more info about this in the README:

https://github.com/fradelg/docker-mysql-cron-backup#restore-from-a-backup

You specify the path to your backup in the command as an argument to the restore.sh script. You can also use the official MariaDB and mount the dump in /docker-entrypoint-initdb.d:

- ${VOLUME_PATH}/backup/latest.${DATABASE_NAME}.sql.gz:/docker-entrypoint-initdb.d/database.sql.gz
steakhutzeee commented 3 years ago

You have more info about this in the README:

https://github.com/fradelg/docker-mysql-cron-backup#restore-from-a-backup

You specify the path to your backup in the command as an argument to the restore.sh script. You can also use the official MariaDB and mount the dump in /docker-entrypoint-initdb.d:

- ${VOLUME_PATH}/backup/latest.${DATABASE_NAME}.sql.gz:/docker-entrypoint-initdb.d/database.sql.gz

Thanks for your reply.

I see that both the command and the env variable point to the backup location. What I mean is, how to tell where to restore the db. The script will automatically read where the db resides from the compose and restore the backup there?

fradelg commented 3 years ago

I'm afraid I don't understand your question.

The DB will be stored wherever you DB manager decides to store the data as if you created this DB from scratch (usually /var/lib/mysql). If you want to persist this data you can mount this directory in your docker host:

-v /my/own/datadir:/var/lib/mysql

The DBMS will read the SQL statements in you backup and populate the file systems with the tables and indices but the path of this storage is not something you want to change (usually).

steakhutzeee commented 3 years ago

I'm afraid I don't understand your question.

The DB will be stored wherever you DB manager decides to store the data as if you created this DB from scratch (usually /var/lib/mysql). If you want to persist this data you can mount this directory in your docker host:

-v /my/own/datadir:/var/lib/mysql

The DBMS will read the SQL statements in you backup and populate the file systems with the tables and indices but the path of this storage is not something you want to change (usually).

Ok will try to explain better. I use Mariadb container by LinuxServer and I persisted the db directory in my compose. To the same compose I added your container. So my question was:

Will your container automatically read the bind mount for my mariadb container and perform a restore there?

Anyway i suppose that as per the container is able to find and backup the db, it's also able to restore to the same dir

fradelg commented 3 years ago

The final storage path of the DB data does not matter for this docker image.

When you use define your MySQL host in the env of this container, you point to your MariaDB service running in your other container. Then, the mysql CLI will connect to the MariaDB service and this MariaDB service must restore the DB in the same location where any other DB would be stored as if you created from scratch.

You can take a look to the restore.sh file to understand what you're doing:

https://github.com/fradelg/docker-mysql-cron-backup/blob/master/restore.sh

steakhutzeee commented 3 years ago

Thank you for the clarification!

fradelg commented 3 years ago

You're welcome!