Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly backup docker container? #2355

Closed
ROODAY opened this issue Jan 28, 2019 · 4 comments
Closed

How to properly backup docker container? #2355

ROODAY opened this issue Jan 28, 2019 · 4 comments

Comments

@ROODAY
Copy link

ROODAY commented Jan 28, 2019

I followed the instructions to run Monica and mysql docker containers via docker-compose, and I have mounted volumes for both of them. My current method of backup is a script that runs daily that zips the mounted volumes for the mysql container and uploads it to Google Drive. However, the volume has been empty ever since I made my container, something I noticed recently. I notice in the Monica dashboard there's an option to export SQL, and that seems be the best option for backing up. Is there a way I can do this automatically via a script on my server? I'd like to be able to generate these SQL dumps and upload them the way I've been doing with the mounted volume.

@Pitasi
Copy link

Pitasi commented Jan 28, 2019

If I'm not wrong, the volume is a storage for documents/photos you upload through Monica, so maybe that's why it's empty for you.

About the database volume, you can backup the SQL like this:

Backup
$ docker-compose exec mysql /usr/bin/mysqldump -u root --password=sekret_root_password monica > monica.sql

Restore
$ cat monica.sql | docker-compose exec mysql /usr/bin/mysql -u root --password=sekret_root_password monica

inside the directory containing your docker-compose.yml, and assuming your mysql service is called mysql. Remember to replace sekret_root_password with the root password that you can set through environment variables within docker compose :)

@ROODAY
Copy link
Author

ROODAY commented Jan 29, 2019

Thanks, that's exactly what I was looking for!

@ROODAY ROODAY closed this as completed Jan 29, 2019
@solarchemist
Copy link

Same setup. Except perhaps more recent stack: Monica v2.13, Docker Compose 1.24.0, Docker 18.09.5. I really appreciate OP asking and @Pitasi taking the time to answer so clearly.

I can confirm that using mysqldump as described above works.
But restore fails with

$ cat monica.sql | docker-compose exec mysql /usr/bin/mysql -u root --password=sekret_root_password monica
the input device is not a TTY

Of course, the containers were up and running at the time (as evidenced by the successful backup operation). I thought perhaps the dump I was trying to restore could be using an old format (it's from an older version of Monica) so I also tried restoring the just-now created dump. But that still gave the same error.

I found an SO answer that suggested using docker (instead of docker-compose) to achieve the same thing, and curiously enough that worked:

docker exec -i $(docker-compose ps -q mysql) mysql -u root --password=sekret_root_password monica < monica.sql

Perhaps someone more well-versed in Docker can explain why the docker-compose approach seems to have stopped working.

@github-actions
Copy link

This issue has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants