PHP - 使用远程服务器创建文件备份(ssh2_exec)

时间:2017-09-18 20:25:47

标签: php ssh

我尝试使用服务器“B”(远程服务器)上的PHP脚本创建服务器“A”的文件备份。我想使用ssh2_exec,因为这个备份将包含很多文件(~1 GB)所以我不能使用例如file_put_contents('ftp:// ...',file_get_contents('/ path / backup)。 zip'))因为我得到:“致命错误允许内存大小”。所以我决定使用ssh2_exec,并且有我的脚本:

$connection = ssh2_connect('host', 222);
ssh2_auth_password($connection, 'nick', 'pass');

$stream = ssh2_exec($connection, '/bin/tar zcf backup.tgz public_html');

它不能正常工作。我不知道如何准备:

  • 应该压缩为备份文件的完整路径(来自服务器“A”),
  • 我要保存此备份的完整路径(在服务器“B”上)。

脚本将在服务器“B”上启动。任何人都可以帮助我,我如何准备一条完整的道路,如:

$full_remote_path = '/home/user/domains/remote_domain.net/public_html/'; // full path to files which should be zipped, on remote server

$full_local_path = '/home/user2/domains/local_domain.net/public_html/backup/'; // full path to save zipped backup on local server

感谢您的帮助。

0 个答案:

没有答案
相关问题