ShahriyarR / MySQL-AutoXtraBackup

MySQL-AutoXtraBackup commandline tool written in Python 3 based on Percona XtraBackup
https://autoxtrabackup.azepug.az/
MIT License
140 stars 79 forks source link

How to run it as a user? #330

Closed BarbzYHOOL closed 5 years ago

BarbzYHOOL commented 5 years ago

I try to run it as a user but i keep getting file permission errors

InnoDB: Failed to create check sector file, errno:13 Please confirm O_DIRECT is supported and remove the file /var/lib/check_sector_size if it exists.
InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to the directory.
InnoDB: Error in opening ./ib_logfile0

@ShahriyarR

BarbzYHOOL commented 5 years ago

/var/lib/mysql/ib_logfile0

belongs to mysql group @ShahriyarR

ShahriyarR commented 5 years ago

@BarbzYHOOL Welcome back :) So based on error it seems to be the Unix system permissions problem. Please see following discussion - maybe it can be useful. https://bugs.mysql.com/bug.php?id=84488

BarbzYHOOL commented 5 years ago

I mean, how do you proceed yourself??

I can change /var/lib/mysql to be owned by a "backup" user or even chmod 777, or maybe create a group "percona" and add users mysql and xtrabackup in it?

What is your way of doing this? do you run it as root? @ShahriyarR

ShahriyarR commented 5 years ago

If you have already spotted that this is exactly the user issue then you can try it to run as sudo at least. From official doc: https://www.percona.com/doc/percona-xtrabackup/LATEST/using_xtrabackup/privileges.html#permissions-and-privileges-needed

Once connected to the server, in order to perform a backup you will need READ, WRITE and EXECUTE permissions at a filesystem level in the server’s datadir.
BarbzYHOOL commented 5 years ago

Of course it works with sudo, but you made a PR https://github.com/ShahriyarR/MySQL-AutoXtraBackup/issues/302 about not needing sudo

So I suppose you know how to proceed to NOT use sudo or root for autoxtrabackup.

So, how do you proceed yourself??

What is your way of doing this? do you run it as root? or with sudo?

How should I proceed? I can change /var/lib/mysql to be owned by a specific "backup" user or even chmod 777, or maybe create a group "percona" and add users "mysql" and "xtrabackup" in it?

BarbzYHOOL commented 5 years ago

Found this solution:

 runuser -s "/bin/sh"  mysql -c "autoxtrabackup --backup -v -l DEBUG" 
BarbzYHOOL commented 5 years ago

what do you think @ShahriyarR :P

ShahriyarR commented 5 years ago

I did not have such issue with my tests and production servers :) What do you suggest to add to autoxtrabackup in term of this?

BarbzYHOOL commented 5 years ago

I think nothing needs to be added but to the documentation eventually but in fact it's something related to xtrabackup, I just asked you because you're cool :P

It's just about permissions and by the way you didn't tell me how you run autoxtrabackup (as root, as sudo, or as a simple user but in that case what are your permissions on /var/lib/mysql etc)

@ShahriyarR

ShahriyarR commented 5 years ago

@BarbzYHOOL ahah :) Let me describe the Percona XtraBackup and autoxtrabackup itself. Percona's tool is for hot-online physical backup for MySQL server. autoxtrabackup is basically Python wrapper command line tool with bunch of bugs :) MySQL server is owned by mysql system user and datadir is owned by mysql user as well so it should not be changed. XtraBackup itself may require root privileges if you are going to parse system files, if you are going to backup to some system folder etc. In general most of us using Percona XtraBackup under sudo or root - so this not a problem and should not be avoided. Consider situation, you have disaster, you have prepared your full and incremental backups and now you need to recover:

Al these kind of steps are going to be possible only with root privileges.

BarbzYHOOL commented 5 years ago

@ShahriyarR ok, I don't remember how autoxtrabackup work for restoring backups but I suppose I can still run it as mysql user lol

I got confused because in one of your PR you talked about sudo for logs, and I still don't understand what was the point if everything else requires sudo

ShahriyarR commented 5 years ago

@BarbzYHOOL it was a specific case where I was testing in one of our test servers without polluting system folders. Mentioned steps are fully automated by autoxtrabackup but still they can be achieved manually as well. So just ignore those user related things and please continue to dig into and to find bugs :)

BarbzYHOOL commented 5 years ago

ok, at least my method works even if it's NOT needed (but i wanted to do it properly, in case a bug erases all my /root :P)