Mysql – Using Jenkins to access thesql files on the same instance


I have a Jenkins installation and running mysql server on the same box. One of my jenkins jobs is supposed to tar up the /var/lib/mysql folder but I get the following error

tar: /var/lib/mysql/mysql: Cannot open: Permission denied

I have added the jenkins user to the mysql group but this has not done anything for me.

Does anyone have any ideas?

Thank you for your help

Best Answer

From memory the mysql database directory is often set with user permissions only. Group permissions are 0. i.e. 0700 or similar.

Doing this backup the way you are doing it could lead to corruption if data is written while you are running tar. So rather than use tar directly, use mysqldump to back up the whole database. Add a jenkins user to mysql that has permissions to run the backup for all of the databases. Then gzip the resulting file. I'd create a script to do this and call it from Jenkins.