mxgross / EasyBackupBundle

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

SQL parameters seemingly not found #48

Closed noseshimself closed 1 year ago

noseshimself commented 1 year ago

Current version of plugin and Kimai2.

The plugin was pulled from git without any modifications or configuration:

image

Running it results in

[2022-10-03 13:20:52] INFO: Start database backup.
[2022-10-03 13:20:52] INFO: Used database: 'mysql'.
[2022-10-03 13:20:52] ERROR: Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases
OR     mysqldump [OPTIONS] --system=[SYSTEMOPTIONS]]
For more options, use mysqldump --help
[2022-10-03 13:20:52] INFO: Start zipping '/opt/kimai/var/easy_backup/2022-10-03_132052/' to '/opt/kimai/var/easy_backup/2022-10-03_132052.zip'.

so it looks like the correct parameters are not found in the Kimai configuration...

noseshimself commented 1 year ago

I did some debugging...

My database configuration doesn't contain a port number (as the database is running on the default port). Your script should generated a mysqldump command that did not work at all:

[2022-10-03 14:25:02] INFO: mysqldump-commandline: '/usr/bin/mysqldump --user=kimai --password=$882934$6166472$1151515 --host=db-bnc-net/kimai --port=3306 --single-transaction --force  --no-tablespaces'.

1) This is probably a result of my specification in the Docker configuration as

    environment:
      - APP_ENV=prod
      - DATABASE_URL=mysql://kimai:$882934$6166472$1151515@db-bnc-net/kimai

and your parsing it going completely wrong (although Kimai likes it that way).

2) You should escape the password on your command line (and yes, I changed my password).

mxgross commented 1 year ago

Thanks for your feedback. I will implement a solution that respects the default port / no port and escapes the password.

mxgross commented 1 year ago

I updated my implementation using parse_url. I tested it with your URL which leads to

array(5) {
  ["scheme"]=>
  string(5) "mysql"
  ["host"]=>
  string(10) "db-bnc-net"
  ["user"]=>
  string(5) "kimai"
  ["pass"]=>
  string(23) "$882934$6166472$1151515"
  ["path"]=>
  string(6) "/kimai"
}

I trim all slashes (/) from the path and I remove the whole --port={port} part when no "port" key exits. This should solve your problem. Please give me feedback about it.

Regarding 2.) password escaping: Do you have any idea how to do this with proc_open when executing command lines without knowing something about the keystore of the machine? Maybe you can configure your machine to work without a password needed for the mysqldump command: https://unix.stackexchange.com/a/227657

noseshimself commented 1 year ago

Thanks. 1) Working as expected now. Sorry for my late answer but I was so concentrated on not getting Covid that the flu (which is just as deadly) caught up with me.

Regarding 2) I can use any password I want so I can obviously create one without any $ sign but you might warn users that the shell may and will interact with the command line it will receive from you.