是否可以使用 MSDeploy 创建站点的远程备份?

是否可以使用 MSDeploy 创建站点的远程备份?

我目前正在使用packagedest 创建站点的备份,如下所示:

msdeploy.exe -source:appHostConfig="Default Web Site",computerName="https://server:8172/MSDeploy.axd?site=Default Web Site",userName="abc",password="xyz",authtype="basic" 
-dest:package="c:\backup\backup-2011.8.2.1000.zip" -verb:sync

此处,目标是本地文件。是否可以将目标设为远程服务器本身的一个位置?我正在从构建服务器运行命令,但我希望在远程服务器上创建并存储备份,而不是将其下载到构建机器上。

这将针对公共服务器运行,因此共享文件夹是不可能的。我还有什么其他选择?

答案1

是的,使用 -source:runCommand,但首先你应该把脚本放在那里(例如批处理)

从:http://sourcecodebean.com/archives/synchronizing-files-and-executing-commands-on-a-remote-server-using-msdeploy/775 下面是一个简单的 PowerShell 脚本,它有两个功能。Send-Files – 将本地文件夹同步到远程服务器。Execute-RemoteCommand – 在远程服务器上执行批处理文件。该文件必须已位于服务器上。

$MSDeployExe = "C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"
$RemoteHost = "http://localhost:80/MsDeployAgentService"
$Credentials = ""
$LocalDir = "C:\temp\LocalDir"
$RemoteDir = "C:\temp\RemoteDir"

function Send-Files {
        param (
                [string]$WebDeployService,
                [string]$LocalDir,
                [string]$RemoteDir,
                [string]$Credentials
        )

        Write-Host "Sending files to $WebDeployService`: $RemoteDir" -ForegroundColor Yellow

        if ($Credentials -ne "") {
                $Credentials = ",getCredentials=" + $Credentials
        }

        & $MSDeployExe "-verb:sync" "-source:dirPath=$LocalDir" "-dest:dirPath=$RemoteDir,computername=$WebDeployService$Credentials" "-verbose"
        $successful = $?

        if (-not $successful) {
                throw "Failed sending files"
        }
}

function Execute-RemoteCommand {
        param (
                [string]$WebDeployService,
                [string]$RemoteDir,
                [string]$BatchFile,
                [string]$Credentials,
                [int]$waitInterval = 15000
        )

        $command = Join-Path $RemoteDir $BatchFile
        Write-Host "Executing $command on $WebDeployService" -ForegroundColor Yellow

        & $MSDeployExe "-verb:sync" "-source:runCommand=’$command’,waitInterval=$waitInterval,waitAttempts=1" "-dest:auto,computername=$RemoteHost$Credentials" "-verbose"

        $successful = $?

        if (-not $successful) {
                throw "Failed executing command"
        }
}

# Test
Send-Files $RemoteHost $LocalDir $RemoteDir $Credentials
Execute-RemoteCommand $RemoteHost $RemoteDir "HelloWorld.bat" $Credentials

相关内容