Forum: Cfengine Help
Subject: MySQL backup via Cfengine3
Author: ro
Link to topic: https://cfengine.com/forum/read.php?3,19623,19623#msg-19623

I really like the concept that cf-execd can be a substitution of regular cron 
jobs. So I tried to let Cfengine handle MySQL database backups. But the 
behavior of cfengine seems strange to me:

The line doing the backups is:

body contain rootshell {
        useshell => "true";
        umask => "077";
        exec_owner => "root";
}
[...]
commands:
        BACKUP_SRV_MYSQL.Hr03_Q1|DO_BACKUP_MYSQL_NOW::
                "/usr/bin/mysqldump --opt --all-databases --user=root 
--add-drop-database | /bin/gzip > 
$(backup_target_dir)/mysql_$(const.dollar)(date +%Y-%m-%d).sql.gz",
                        contain => rootshell,
                        classes => 
PromiseRepaired("repaired_MySQLBackup_backup");


In the root's home directory there is a .my.cnf file:

-rw-------  1 root root    502 2010-12-03 16:06 .my.cnf


which contains:


user=root
password=MYPASSWORD


user=root
password=MYPASSWORD


Now, when the promise is run manually, the backup is created properly:

r...@myhost:~# cf-agent -K -b MySQLBackup -D 
BACKUP_SRV_MYSQL,DO_BACKUP_MYSQL_NOW
R: Performed MySQL backup


However, when the promise is executed by cf-execd, I get a permission error:

Q: ".../mysqldump --op": mysqldump: Got error: 1045: Access denied for user 
'root'@'localhost' (using password: NO) when trying to connect
I: Last 1 QUOTed lines were generated by promiser "/usr/bin/mysqldump --opt 
--all-databases --user=root --add-drop-database | /bin/gzip > 
/srv/backup/mysql/mysql_$(date +%Y-?m-?d).sql.gz"
R: Performed MySQL backup


Shouldn't the result be the same, regardless if run manually or automatically?

Cheers,
Robert

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to