使用python的子进程使用带引号的参数运行rsync

时间:2017-06-08 07:55:01

标签: python subprocess rsync

我有一些使用rsync模块执行subprocess的自动备份脚本。 在指定ssh身份文件的新要求之前一切正常。

根据rsync手册,ssh标识应作为带引号的字符串传递:

-e "ssh -i /home/username/.ssh/identity"

但这将无法在subprocess中运行:

subprocess.Popen(['rsync', '-avz', '-e "ssh -i /home/username/.ssh/identity"', '~/Downloads', 'root@remote_server:/lvm/archive/backup'])
<subprocess.Popen object at 0x7fd111939710>
rsync: Failed to exec ssh -i /home/username/.ssh/identity: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.0]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in IPC code (code 14) at io.c(226) [sender=3.1.0]

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:1)

subprocess.Popen(['rsync', '-avz', '-e', 'ssh -i /home/username/.ssh/identity', '~/Downloads', 'root@remove_server:/lvm/archive/backup'])