如何在 windows 任务计划程序上安排 azcopy?

How to schedule azcopy on windows task schedueler?

目标 将我的虚拟驱动器(Azure 文件共享)同步到 Azure blob 存储容器

解决方法 对于此解决方案,我使用的是 azcopy。当我 运行 使用我创建的批处理文件进行 azcopy 时,一切都是 运行ning 正确。

但我也想安排这个,比如每天晚上。 为此,我将使用 windows 任务调度程序。

Windows tasks scheduler 运行s bat 文件正确。我的 bat 文件还创建了一个日志文件。当我 运行 手动与任务调度程序时,日志文件中的输出不同。

批处理文件:

@echo off
IF EXIST C:\inetpub\wwwroot\tasks\azcopy_logs.txt (
    del C:\inetpub\wwwroot\tasks\azcopy_logs.txt
)
set LOGFILE=C:\inetpub\wwwroot\tasks\azcopy_logs.txt
call :LOG > %LOGFILE%
exit /B

:LOG

SET source="Y:\my-folder"
echo %source%
SET dest=^"https://TEST.blob.core.windows.net/my-container/?sv=2019-02-02^&ss=bfqt^&srt=sco^&sp=rwdlacup^&se=2120-02-26T14:56:15Z^&st=2020-02-26T06:56:10Z^&spr=https^&sig=TEST^"

echo %dest%

azcopy.exe sync %source% %dest%


exit

运行宁手动

时输出
"Y:\my-folder"
"https://TEST.blob.core.windows.net/my-container/?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2120-02-26T14:56:15Z&st=2020-02-26T06:56:10Z&spr=https&sig=TEST"

Job a84acee9-1796-f44b-4852-530d052db5a0 has started
Log file is located at: C:\Users\x\.azcopy\a84acee9-1796-f44b-4852-530d052db5a0.log


0 Files Scanned at Source, 0 Files Scanned at Destination
334 Files Scanned at Source, 672 Files Scanned at Destination, 2-sec Throughput (Mb/s): 0
The source and destination are already in sync.

输出 运行 任务调度程序

"Y:\my-folder"
"https://TEST.blob.core.windows.net/my-container/?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2120-02-26T14:56:15Z&st=2020-02-26T06:56:10Z&spr=https&sig=TEST"

Cannot perform sync due to error: sync must happen between source and destination of the same type, e.g. either file <-> file, or directory/container <-> directory/container

任务调度器xml定义

 <?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2020-02-25T13:30:25.4791113</Date>
    <Author>my-user</Author>
    <URI>\azcopy\my task name</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2020-02-25T13:29:16</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>my-user-id</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\inetpub\wwwroot\tasks\azcopy.bat</Command>
      <WorkingDirectory>C:\inetpub\wwwroot\tasks\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

终于找到并解决了问题

Windows 任务计划程序没有权限安装 azure 文件共享驱动器。

解法: 将源驱动器 (SET source="Y:\my-folder") 更改为 UNC 路径 (SET source="\TEST.file.core.windows.net\my-container\my-folder")