You are not logged in.

#1 2018-05-03 11:48:45

K3N8
Member
From: The Netherlands
Registered: 2011-11-02
Posts: 62

MySQL backup through systemctl

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

#2 2018-05-03 12:01:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: MySQL backup through systemctl

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

#3 2018-05-03 12:09:25

K3N8
Member
From: The Netherlands
Registered: 2011-11-02
Posts: 62

Re: MySQL backup through systemctl

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

#4 2018-05-03 12:13:06

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: MySQL backup through systemctl

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

#5 2018-05-04 17:01:16

K3N8
Member
From: The Netherlands
Registered: 2011-11-02
Posts: 62

Re: MySQL backup through systemctl

@progandy Bedankt voor je tip!


Arch Linux x86_64 LTS

Offline

Board footer

Powered by FluxBB