I'm creating a script that moves log files created by mysql.
The files I need to move are created regularly and are something like this
gorf@212370 ~/Desktop $ ls -l /mysql-log/
-rw-rw---- 1 mysql mysql 148 Nov 13 18:39 bin-log.000019
-rw-rw---- 1 mysql mysql 126 Nov 13 18:42 bin-log.000020
-rw-rw---- 1 mysql mysql 148 Nov 13 18:44 bin-log.000021
-rw-rw---- 1 mysql mysql 148 Nov 13 18:50 bin-log.000022
-rw-rw---- 1 mysql mysql 148 Nov 13 18:50 bin-log.000023
-rw-rw---- 1 mysql mysql 107 Nov 13 18:50 bin-log.000024
-rw-rw---- 1 mysql mysql 1456 Nov 13 18:50 bin-log.index
and the user I use to move the files is
gorf@212370 ~/Desktop $ groups gorf
gorf : gorf adm cdrom sudo dip plugdev lpadmin sambashare mysql
Since the files are owned by mysql, and the user "gorf" belongs to the "mysql" group, I was expecting to be able to move the files. However, if I try to move the files, I get permission denied
gorf@212370 ~/Desktop $ mv /mysql-log/bin-log.000023 ./
mv: cannot move ‘/mysql-log/bin-log.000023’ to ‘./bin-log.000023’: Permission denied
,but if I copy them
gorf@212370 ~/Desktop $ cp /mysql-log/bin-log.000023 ./
that's OK.
In the script, I need to move the files since these are part of an incremental backup. One solution would be to run the script as root, but, for security reasons, I'm looking for more elegant solutions.
What can I do in order to solve this problem?
The reason that you can't delete the files is because root owns the /mysql-log directory. You need to change ownership to the group 'mysql':