简体   繁体   English

Windows 8.1任务计划程序在未登录的情况下不会执行Rsync / SSH

[英]Windows 8.1 Task Scheduler Won't Execute Rsync/SSH Without being Logged On

I've created and scheduled a batch file in Windows 8.1 (to perform rsync offsite backups through an SSH tunnel) and I can run it: 我已经在Windows 8.1中创建并计划了一个批处理文件(以通过SSH隧道执行rsync异地备份),并且可以运行它:

  • manually 手动地
  • through task scheduler manually when I right click -> Run 右键单击->运行时,手动通过任务计划程序
  • through task scheduler automatically when I am logged on and it's scheduled to run at a given time 通过任务计划程序自动登录到我并计划在给定时间运行

... but when I'm not logged on, it just sits at "Running" even though I've set it as follows: ...但是当我未登录时,即使我将其设置如下,它也位于“正在运行”:

  • user=me (I'm a member of admin group) user = me(我是管理员组的成员)
  • run whether logged on or not 无论是否登录运行
  • run with highest privileges 以最高特权运行

I can see in Task Manager that rsync.exe and ssh.exe are running, so it must be hanging on the rsync/ssh call. 我可以在任务管理器中看到rsync.exe和ssh.exe正在运行,因此它必须挂在rsync / ssh调用上。 That leads me to believe the problem is that, even though I've explicitly set the user name, something isn't really running as me? 这使我相信问题是,即使我已经明确设置了用户名,也没有像我这样真正运行吗? (sidebar: I've also tried running the task as SYSTEM user - no luck there either) (侧边栏:我也尝试过以SYSTEM用户身份运行任务-那里也没有运气)

The command I'm issuing looks like this: 我发出的命令如下所示:

rsync --archive --verbose --human-readable --hard-links --delete --exclude '*.log' --exclude '*log*.*' -e  "%CWRSYNCBIN%\ssh -p 22103 -i C:\Users\test\.ssh\id_rsa" "/cygdrive/c/Users/test/Downloads" admin@1.2.3.4:/path/to/remote 1> %REPORTLOG% 2> %ERRORLOG%

Any ideas? 有任何想法吗? (thanks!) (谢谢!)

This seems to be problem with home directory and non-interactive environment in scheduled jobs in newer Windows version (starting from Server 2008 and Vista?). 这似乎是主目录和非交互环境在较新的Windows版本(从Server 2008和Vista开始)中的计划作业中的问题。 I find it in few discussions, but with not much info to solve it: 我在很少的讨论中找到了它,但是没有足够的信息来解决它:

My solution was: 我的解决方案是:

  • set task to run under user that is proven to be able to finish rsync, set run whenever user are logged on or not, I also set to does not save password, 将任务设置为在被证明能够完成rsync的用户下运行,设置无论用户是否登录都运行的时间,我还设置为不保存密码,
  • find location of .ssh folder under this user (in his home directory), 在该用户下(在其主目录中)查找.ssh文件夹的位置,
  • copy .ssh to simplier path to use it in HOME variable ( SET HOME=D:\\CWRSYNC\\HOME ), 将.ssh复制到更简单的路径以在HOME变量中使用它( SET HOME=D:\\CWRSYNC\\HOME ),
  • use following script to run rsync: 使用以下脚本运行rsync:



    @ECHO OFF
    SETLOCAL
    SET CWRSYNCHOME=D:\CWRSYNC
    SET HOME=D:\CWRSYNC\HOME
    SET CWOLDPATH=%PATH%
    SET PATH=%CWRSYNCHOME%;%PATH%
    rsync.exe -rtvz --delete /cygdrive/b/ user@192.168.1.2:/volume1/NetBackup/ >> D://nas-backup-log.txt

When I experienced this problem on Windows Server 2012 R2, I found SSH.exe was experiencing a permissions error when attempting to create a known_hosts file, despite the task running with an admin's credentials and with highest privileges. 当我在Windows Server 2012 R2上遇到此问题时,我发现SSH.exe在尝试创建known_hosts文件时遇到权限错误,尽管该任务以管理员的凭据和最高权限运行。

The solution was to point to the user's existing known_hosts file using the UserKnownHostsFile SSH option: 解决方案是使用UserKnownHostsFile SSH选项指向用户现有的known_hosts文件:

rsync -e "ssh -i sshkey -o UserKnownHostsFile path/to/known_hosts" source dest

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

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