0

所以我一直在尝试为 rsync 编写一个 launchctl 守护进程,以便它每晚远程备份我的笔记本电脑。

launchctl 守护进程运行良好,它使用 root 用户调用 rsync,并指示 rsync 使用 ssh,并从我的用户目录中获取密钥文件。这就是有趣的地方。无论我做什么,ssh 都会抛出以下错误:rsync: Failed to exec ssh -i /Users/anthony/.ssh/id_rsa: No such file or directory (2)

钥匙确实在那里。如果我从命令行单独调用 ssh,我可以从我的用户帐户和 root 帐户中使用该密钥。我假设这与launchctl的范围或特权有关?下面是 launchctl 正在使用的 plist 文件。我真的很感激这方面的一些帮助。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>UserName</key>
    <string>root</string>
    <key>Label</key>
    <string>com.anthony.remoteBackup</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>StartCalendarInterval</key>
        <dict>
            <key>Hour</key>
            <integer>23</integer>
            <key>Minute</key>
            <integer>00</integer>
        </dict>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/rsync</string>
        <string>-azb</string>
        <string>--exclude=.*</string>
        <string>--exclude=.*/</string>
        <string>--backup-dir="/home/anthony/Documents/Old Remote Backup/macbook_air/"</string>
        <string>--suffix=.old</string>
        <string>--delete</string>
        <string>--delete-excluded</string>
        <string>-e "ssh -i /Users/anthony/.ssh/id_rsa"</string>
        <string>/Users/anthony/Documents</string>
        <string>anthony@remote_domain_name:"/home/anthony/Documents/Remote Backups/macbook_air/"</string>
    </array>
    <key>StandardOutPath</key>
    <string>/tmp/remote_backup_test</string>
    <key>StandardErrorPath</key>
    <string>/tmp/remote_backup_test</string>
</dict>
</plist>

这是来自 remote_backup_test 的标准错误

rsync: Failed to exec ssh -i /Users/anthony/.ssh/id_rsa: No such file or directory (2)
rsync error: error in IPC code (code 14) at /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-54.120.1/rsync/pipe.c(86) [sender=2.6.9]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-54.120.1/rsync/io.c(453) [sender=2.6.9]
4

1 回答 1

0

我怀疑问题是你如何传递论点。您在几个参数中的双引号是 shell 语法,但ProgramArguments数组的元素不会被 shell 解析,所以它们不应该在那里。最重要的是,后面的空格-e旨在由 shell 解析为参数分隔符,因此请替换:

        <string>-e "ssh -i /Users/anthony/.ssh/id_rsa"</string>

和:

        <string>-e</string>
        <string>ssh -i /Users/anthony/.ssh/id_rsa</string>

--backup-dir=并从和 target ( anthony@...) 参数中删除双引号。

于 2020-09-13T20:38:24.097 回答