1

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

5
  • Did you stop the database first?
    – hookenz
    Mar 17, 2014 at 8:07
  • I did not. I will try that and let you know how it goes. Thank you Mar 17, 2014 at 8:08
  • I have tried the jenkins job with the database stopped and still received the same issue Mar 17, 2014 at 8:25
  • Have you checked that the database files and /var/lib/mysql directory are group-readable? Mar 17, 2014 at 8:36
  • @TeroKilkanen Thank you for your comment. Changing the permissions on the folders/files have fixed the issue. Mar 17, 2014 at 8:55

2 Answers 2

0

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.

1
  • Thank you for your answer, we actually have a process to produce a more conventional sql dump. This is approach I'm working on here is about experimenting. Cheers Mar 17, 2014 at 8:58
-1

Running these commands has allowed my to tar the folder

find /var/lib/mysql -type d -exec sudo chmod 2775 {} +
find /var/lib/mysql -type f -exec sudo chmod 0664 {} +
1
  • But that opens up your database for potentially other users on the system to view more than necessary. Use 2770 & 0660 instead. And if you're going to just tar it up make sure you stop mysqld first.
    – hookenz
    Mar 18, 2014 at 0:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .