It created a .tar.gz file, but when opening the file it only contains a backup-my.cnf..?!
You must use the -i
option for tar to extract or view the contents of a tar file created by Percona XtraBackup. This is documented, and a reminder is output at the end of the innobackupex process:
. . .
130630 10:40:23 innobackupex: Connection to database server closed
innobackupex: You must use -i (--ignore-zeros) option for extraction of the tar stream.
130630 10:40:23 innobackupex: completed OK!
Omitting the -i
option results in the behavior you saw: only the first file in the tar archive is visible.
Then I tried to run the first working command from the webserver... No file is created... PHP already has access to the target directory
The innobackupex process must have read privileges on the data and log files under the MySQL datadir, in addition to write privilege to save the output of the backup.
You should have seen errors like this:
130630 10:36:20 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Error in opening ./ibdata1
But it was probably lost because PHP's exec()
call discards stderr output.
Re your comment of 8/4:
Okay I tried this myself with the most recent XtraBackup and most recent Percona Server.
I need to test this from the shell so I can see error output. When you run it only from your PHP script, you aren't seeing the errors as they occur. Once you get it working, you should be able to change the gid to www-data and have it continue to work.
I tested by changing the group ownership of all files to my own user's gid.
$ cd /var/lib/mysql # use your datadir if it is different
$ chgrp -R billkarwin .
No need to chmod anything on a default installation. But your file permissions are probably not right at this point, so you need to restore them to something that works:
$ cd /var/lib/mysql # use your datadir if it is different
$ chmod -R 660 .
$ chmod 770 . */.
$ chmod 777 mysql.sock
Then I can run innobackupex, but I have to specify the mysql credentials:
$ innobackupex --user=root --password=XXXX /tmp
130804 08:56:33 innobackupex: Connecting to MySQL server with DSN
'dbi:mysql:;mysql_read_default_group=xtrabackup' as 'root' (using password: YES).
130804 08:56:33 innobackupex: Connected to MySQL server
. . .
130804 09:53:46 innobackupex: Connection to database server closed
130804 09:53:46 innobackupex: completed OK!
Note that you could also add an [xtrabackup] group to your user's own $HOME/.my.cnf so you don't have to put the credentials on the command-line.
$ cat > ~/.my.cnf
[xtrabackup]
user=root
password=XXXX
^D
$ innobackupex /tmp