giandonatoinverso / PHP-Dynamic-Qr-code

PHP Dynamic Qr code is a script that allows the generation and saving of dynamic and static QR codes
MIT License
281 stars 79 forks source link

Backup / Restore - how to do it right ? #87

Open n00bsi opened 9 months ago

n00bsi commented 9 months ago

Hello, did I understand right that the Directories:

/var/lib/docker/volumes/php-dynamic-qr-code_php_dynamic_qrcode_db_data/_data/ /var/lib/docker/volumes/php-dynamic-qr-code_php_dynamic_qrcode_saved_qrcode_data/_data/

is there all needed data stored ?

And I need to create a mysql-dump because the DB is open if the docker container: php-dynamic-qr-code-php-dynamic-qrcode-db is running.

Backup

docker exec -it <Container ID> /usr/bin/mysqldump -uroot -pchangeme qrcode --result-file=/var/lib/mysql/qrcode.sql

tar the directories:

/var/lib/docker/volumes/php-dynamic-qr-code_php_dynamic_qrcode_db_data/_data/ 
/var/lib/docker/volumes/php-dynamic-qr-code_php_dynamic_qrcode_saved_qrcode_data/_data/ 
sudo tar cvf - /var/lib/docker/volumes/php-dynamic-qr-code_php_dynamic_qrcode_db_data/_data/ | gzip -9 > db.tar.gz
sudo tar cvf - /var/lib/docker/volumes/php-dynamic-qr-code_php_dynamic_qrcode_saved_qrcode_data/_data/ | gzip -9 > qrcode.tar.gz

How is the restore way:

  1. create a new VM
  2. install docker
  3. git clone https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code
  4. docker compose build --no-cache && docker compose up -d
  5. untar the backups of
sudo su -
cd /
tar xvfz /path/to/db.tar.gz
tar xvfz /path/to/qrcode.tar.gz
  1. clean db import the mysql-dump file

clean.sql

USE qrcode;
drop table dynamic_qrcodes;
drop table static_qrcodes;
drop table users;
docker exec -it <Container ID> /bin/bash
/usr/bin/mysql -uroot -pchangeme qrcode < /var/lib/mysql/clean.sql
/usr/bin/mysql -uroot -pchangeme qrcode < /var/lib/mysql/qrcode.sql
exit
giandonatoinverso commented 9 months ago

Did you tested this procedure ?

n00bsi commented 9 months ago

Did you tested this procedure ?

yes, but I was more a question if there is a better way to do that I belive the db backup could be reduced the save only the qrcode.sql file because the other files for db will be created when build a new VM + new container

if you try on a existing system you need to clean up

Clean UP

cd PHP-Dynamic-Qr-code
docker compose down

docker stop $(docker ps -aq)
docker system prune -a
docker system prune --volumes
docker rmi $(docker images -aq)

docker volume ls
docker volume rm <vol name1>
docker volume rm <vol name2>

cd PHP-Dynamic-Qr-code
docker compose build --no-cache && docker compose up -d
giandonatoinverso commented 9 months ago

Yes, absolutely. The db image contains only the sql file, the others are created from the image itself