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

Paul Sheldrake
  • 537
  • 1
  • 6
  • 14

2 Answers2

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.

hookenz
  • 14,472
  • 23
  • 88
  • 143
  • 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 – Paul Sheldrake Mar 17 '14 at 08: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 {} +
Paul Sheldrake
  • 537
  • 1
  • 6
  • 14
  • 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 '14 at 00:31