简体   繁体   English

通过PHP进行SSH备份问题

[英]SSH backup via PHP problem

I am trying to backup all the files on our server using some SSH commands via PHP and I have a script working to some extent. 我正在尝试通过PHP使用一些SSH命令来备份服务器上的所有文件,并且我的脚本在某种程度上可以正常工作。

The problem is that only some of the folders actually contain any files but the folder structure seems to be correct though. 问题是只有一些文件夹实际上包含任何文件,但是文件夹结构似乎是正确的。

This is the script I am using: 这是我正在使用的脚本:

<?php
   $output = `cd /
   ls -al
   tar -cf /home/b/a/backup/web/public_html/archive.tar home/*`;

   echo "<pre>$output</pre>";
?>

I cant even view the files via SSH commands, an example of this is the test account. 我什至无法通过SSH命令查看文件,例如测试帐户。 If I use the following command I am unable to view the website files. 如果使用以下命令,则无法查看网站文件。

<?php
   $output = `cd /home/t/e/test/
   ls -alRh`;

   echo "<pre>$output</pre>";
?>

But if I use the same commands on the a different account I am able to see and download of the website files. 但是,如果我在其他帐户上使用相同的命令,则可以查看和下载网站文件。

Is this a permission problem or am I missing something in my script? 这是权限问题,还是我的脚本中缺少某些内容?

Thanks 谢谢

I think it permission problem, try to give apache user(or what you set it) permission to read /home/* directory's. 我认为这是权限问题,请尝试授予apache用户(或您设置的权限)读取/home/*目录的权限。 To find the user name that used by apache service run this: For linux: 要查找apache服务使用的用户名,请运行以下命令:对于linux:

egrep -iw --color=auto 'user|group' /etc/httpd/conf/httpd.conf

For FreeBSD: 对于FreeBSD:

egrep -iw --color=auto '^user|^group' /usr/local/etc/apache22/httpd.conf

My guess is that PHP is running in a chroot. 我的猜测是PHP在chroot中运行。

If you just want to execute a backup, consider doing it in a different language. 如果您只想执行备份,请考虑使用其他语言。 Especially if it is just a sequence of UNIX commands, write a shell script. 特别是如果它只是一系列UNIX命令,请编写一个Shell脚本。 Perhaps more details on what this script will be used for and who is providing and maintaining your hosting will be useful. 也许有关此脚本的用途以及谁提供和维护主机的更多详细信息将很有用。

ls -l / | grep home

the output will be like this: 输出将是这样的:

lrwxr-xr-x   1 root  wheel        8 Mar 30 14:13 home -> usr/home

In my case, the owner is root , and the root user its primary group is wheel , so now we add www-data user to wheel group so he can list files in there: 在我的情况下,所有者是root用户的主要组是wheel ,所以现在我们将www-data用户添加到wheel组,以便他可以在其中列出文件:

usermod -a -G wheel www-data

You can download some files because they located in directory owned by www-data user, and when you can't, www-data has no permission in that. 您可以下载一些文件,因为它们位于www-data用户拥有的目录中,而如果您不能下载,则www-data中没有任何权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM