BackupAliases.

RestoreSqlBackup(ICakeContext, string, FilePath, RestoreSqlBackupSettings) Method

Summary

Restores a database from a backup file.
Assembly
Cake.SqlServer.dll
Namespace
Cake.SqlServer
Containing Type
BackupAliases

Syntax

public static void RestoreSqlBackup(this ICakeContext context, string connectionString, FilePath backupFile, RestoreSqlBackupSettings settings)

Examples

    #addin "nuget:?package=Cake.SqlServer"

    Task("Restore-Database")
        .Does(() =>
        {
            var connString = @"data source=(localdb)\MSSqlLocalDb";
            var backupFile = new FilePath("C:/tmp/myBackup.bak");
            RestoreSqlBackup(connString, backupFile, new RestoreSqlBackupSettings() 
               {
                     NewDatabaseName = "RestoredFromTest.Cake",
                     NewStorageFolder = new DirectoryPath(System.IO.Path.GetTempPath()), // place files in Temp folder
                     WithReplace = true, // tells sql server to discard non-backed up data when overwriting existing database
               }); 
        });

Attributes

Type Description
CakeMethodAliasAttribute

Parameters

Name Type Description
context ICakeContext The Cake context.
connectionString string The connection string. You may want to connect to master database for this operation.
backupFile FilePath Absolute path to .bak file
settings RestoreSqlBackupSettings Settings for restoring database

Return Value

Type Description
void