Rsync to Network Share works from cmd but fails from Scheduled Task
rsync at raf.org
Mon Mar 30 03:23:09 UTC 2020
Leon Vanderploeg via rsync wrote:
> I have written a C program that runs on Windows servers and does overhead
> and reporting for backup administration. The program calls rsync for the
> actual data copy function. It copies data from a remote system to a local
> drive and that works fine. However, I have recently made changes to copy
> the data to a mapped drive on a NAS device instead of the local drive.
> The changes work fine when run from a command line, but fail when run from
> a scheduled task or cron job:
> rsync: mkdir "/cygdrive/q/restores" failed: No such file or directory
> rsync error: error in file IO (code 11) at main.c(675) [Receiver=3.1.2]
> Note: The folder already exists and permissions are open for Administrator.
> Command line that works is bash command to call the C program under
> Administrator login.
> Scheduled task built as Administrator with or without highest privileges
> Tried Cron entry built under Administrator and it fails.
> Here is the Rsync command (abbreviated) called by the C program:
> rsync -rltgoD --chmod=Du+w,u+r,u+x -e "ssh -p 33222 -i
> \"/cygdrive/c/Users/administrator/.ssh/id_rsa\"" --stats --files-from=/...
> -vv --exclude-from=/.... <usr>@remote:/<remote_loc> /cygdrive/q/restores
> Note: q is the mapped drive to the NAS share.
> So, what can be done to track this down? Why would running as a scheduled
> task or cron job fail when command line works? I am willing to do any kind
> of tracing if someone can provide directions on how to do that.
> Thanks in advance,
I think the most likely reason is that when you execute
the command interactively, you are logged into Windows
locally and your cached credentials are used to connect
to the mapped drive. But that's not the case when the
task is scheduled, and so the mapped drive isn't mapped
when the scheduled task is attempted.
Similarly, with Cygwin, you can only see
/cygdrive/q/... while you are accessing it locally. If
you ssh to a Windows host with Cygwin and sshd running,
you can't see any mapped drives that are accessible to
the local user, even if you ssh in as the same user.
You will have to map the drive in the scheduled task
before invoking rsync, and then unmap the drive
afterwards. I don't know how to do that or handle the
credentials that would be needed, but I think that's
where to look.
More information about the rsync