它创建了一个 .tar.gz 文件,但是在打开文件时它只包含一个 backup-my.cnf ..?!
您必须使用-i
tar 选项来提取或查看 Percona XtraBackup 创建的 tar 文件的内容。这已记录在案,并在 innobackupex 流程结束时输出提醒:
. . .
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!
省略该-i
选项会导致您看到的行为:只有 tar 存档中的第一个文件可见。
然后我尝试从网络服务器运行第一个工作命令...没有创建文件... PHP 已经可以访问目标目录
innobackupex 进程必须对 MySQL datadir 下的数据和日志文件具有读取权限,此外还必须具有写入权限以保存备份的输出。
你应该看到过这样的错误:
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
但它可能丢失了,因为 PHP 的exec()
调用丢弃了 stderr 输出。
回复您对 8/4 的评论:
好的,我自己使用最新的 XtraBackup 和最新的 Percona Server 进行了尝试。
我需要从 shell 测试它,这样我才能看到错误输出。当您只从您的 PHP 脚本运行它时,您看不到错误的发生。一旦你让它工作,你应该能够将 gid 更改为 www-data 并让它继续工作。
我通过将所有文件的组所有权更改为我自己用户的 gid 进行了测试。
$ cd /var/lib/mysql # use your datadir if it is different
$ chgrp -R billkarwin .
在默认安装中无需 chmod 任何内容。但是此时您的文件权限可能不正确,因此您需要将它们恢复为有效的东西:
$ cd /var/lib/mysql # use your datadir if it is different
$ chmod -R 660 .
$ chmod 770 . */.
$ chmod 777 mysql.sock
然后我可以运行 innobackupex,但我必须指定 mysql 凭据:
$ 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!
请注意,您还可以将 [xtrabackup] 组添加到用户自己的 $HOME/.my.cnf 中,因此您不必将凭据放在命令行上。
$ cat > ~/.my.cnf
[xtrabackup]
user=root
password=XXXX
^D
$ innobackupex /tmp