You are not logged in.
Hi,
I have a problem getting my backup script working through systemctl. Here are my files:
mysql_dump.service:
[Unit]
Description=MySQL Backup Script
[Service]
Type=oneshot
EnvironmentFile=/root/.my.cnf
ExecStart=/root/scripts/mysql_dump.sh
mysql_dump.timer:
[Unit]
Description=Run script every day at 04:00
[Timer]
OnCalendar=04:00:00
Unit=mysql_dump.service
[Install]
WantedBy=default.target
Here is the error:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
It seems "my.cnf" is not loaded.
Last edited by K3N8 (2018-05-03 11:49:58)
Arch Linux x86_64 LTS
Offline
You don't use any environment variables in your ExecStart line, so there's no point in including the EnvironmentFile. If you use those variables in the script, you need to define them or source that file from the script.
EDIT: It seems env variables included in the service file are exported and should be available to the child process. But just the same, your approach seems a bit complicated for what you are trying to do. But the error is likely in the files you have not shown us. What is in the script and environment file?
Also note that the SQL error is actually what you get when you try to log in with a non-existing database user. Have you created a database user root@localhost? This is *not* the same as having a root user on the system.
Last edited by Trilby (2018-05-03 12:08:36)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
OK. I just thought it was possible to use the EnvironmentFile option. Thank you, I'll just hard code it in the script.
Last edited by K3N8 (2018-05-03 12:09:44)
Arch Linux x86_64 LTS
Offline
If you want your script to be dynamic, then a simple way would be to set my.cnf with a commandline parameter
ExecStart=/my/script.sh /path/to/config
script.sh:
#!/bin/sh
some_command --configfile "$1"
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
@progandy Bedankt voor je tip!
Arch Linux x86_64 LTS
Offline