mxgross / EasyBackupBundle

Kimai 2 Plugin for easier backups
MIT License
24 stars 6 forks source link

Docker Compatibility #41

Closed DustyArmstrong closed 2 years ago

DustyArmstrong commented 2 years ago

Hi there,

I am using the Docker containers as provided by Tobybatch. I'm hoping to use Easy Backup but I'm having some trouble with the plugin and wondered if you may have had any experience with this use case.

When I tried to run a backup, I received the following error:

NOTICE: PHP message: request.CRITICAL: Uncaught PHP Exception Symfony\Component\Filesystem\Exception\IOException: "Failed to touch "/opt/kimai/var/easy_backup/easybackup.log"." at /opt/kimai/vendor/symfony/filesystem/Filesystem.php line 151 {"exception":"[object] (Symfony\\Component\\Filesystem\\Exception\\IOException(code: 0): Failed to touch \"/opt/kimai/var/easy_backup/easybackup.log\". at /opt/kimai/vendor/symfony/filesystem/Filesystem.php:151)"} []

When I went to that directory /opt/kimai/var/easy_backup it wasn't there, so I created it. Is this expected behavior?

I was able to run a backup after this, however the SQL database did not backup successfully.

[2021-11-13 00:03:23] INFO: Start database backup.
[2021-11-13 00:03:23] INFO: Used database: 'mysql'.
[2021-11-13 00:03:23] ERROR: mysqldump: 'Usage: mysqldump [OPTIONS] database [tables]'.
[2021-11-13 00:03:23] ERROR: mysqldump: 'OR     mysqldump [OPTIONS] --databases DB1 [DB2 DB3...]'.
[2021-11-13 00:03:23] ERROR: mysqldump: 'OR     mysqldump [OPTIONS] --all-databases'.
[2021-11-13 00:03:23] ERROR: mysqldump: 'OR     mysqldump [OPTIONS] --system=[SYSTEMOPTIONS]]'

My SQL server URL is perhaps not what the plugin is expecting due to it being containerized:

DATABASE_URL=mysql://user:password@sqldb/kimai

Can I format the command(s) in such a way to make the connection across the containers? Which .env file is read from, the one in /opt/kimai/.env?

I also have an exclamation for git rev-parse HEAD, though I do have git installed.

Finally, thank you for the plugin.

DustyArmstrong commented 2 years ago

So I changed the default entries:

/usr/bin/mysql --user={user} --password={password} --host={host} --port={port} {database} < {sql_file}

/usr/bin/mysqldump --user={user} --password={password} --host={host} --port={port} --single-transaction --force {database}

To the normal credentials as a test:

/usr/bin/mysql --user=myusername --password=mypassword --host=hostIP --port=3306 kimai < backup

This was successful, so it suggests that the .env file is not being read as expected or it is reading a different one than what the container uses.

mxgross commented 2 years ago

Hello, I have no experience in docker or running kimai2 inside a docker. The .env that is used should be the one in the same directory like the .env.dist by default.

DustyArmstrong commented 2 years ago

No problem, thanks for the plugin.

darioseidl commented 2 years ago

Thanks @DustyArmstrong for the hint about the mysql connection params. Using hardcoded host and database instead of the params in curly braces worked for me.

I think there my be a small bug in parsing the DATABASE_URL, it looks like it's taking sqldb/kimai as host from DATABASE_URL=mysql://user:password@sqldb/kimai, where sqldb should be the host and kimai should be the database, but it's no big deal.

My PHP is a bit rusty, but it looks like in this line, dbHost ist assigned the the substring after @, where is should be the substring between @ and /: https://github.com/mxgross/EasyBackupBundle/blob/06d8b7bd356cfa3964d96b1c00267dd959f3348c/Controller/EasyBackupController.php#L434

mxgross commented 2 years ago

Hi @darioseidl , thanks, yes you are right. I think it is just a constellation that I did not think of. I will change it when I have time :)