MSBuild extensionpack: verify backup remote

455 views Asked by At

I am trying to backup a database on a remote database server and then verify that backup file.

The backup works well but when I try to verify the backup the build fails with an error:

DataFilePath not found: c:\DatabaseBackups\MyDB.bak

I use the following xml build file on my local computer:

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
        <SqlInstance>myremoteserver</SqlInstance>
        <ProductionBackup>c:\DatabaseBackups\MyDB.bak</ProductionBackup>
        <SqlUserName>user</SqlUserName>
        <SqlPassword>pass</SqlPassword>
        <DatabaseName>MyDB</DatabaseName>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="BackupDB">
        <!-- Backup a database -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="Backup" DatabaseItem="$(DatabaseName)" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="$(ProductionBackup)"/>
        <!-- Verify a database backup -->
        <MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="$(ProductionBackup)"/>
    </Target>
</Project>

This build file works fine if I run the backup and verification on my local machine but fails when I change the MachineName to a remote server. I believe that when searching for the backup file MS Build searches on my local machine and not on the remote machine. How can I tell MS Build to search the remote server for the backup file?

1

There are 1 answers

0
James Woolfenden On

Just provide the file path as a unc path. Make the destination shared to your user and it should work fine. If youve admin rights:

<MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="\\$(SQLInstance)\C$\DatabaseBackups\MyDB.bak"/>

Otherwise share the databaseBackups folder to your user:

<MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="\\$(SQLInstance)\DatabaseBackups\MyDB.bak"/>