Invoke-SQLMigrateDB
SYNOPSIS
Migrate a database between SQL servers.
SYNTAX
Manual (Default)
Invoke-SQLMigrateDB -SourceServer <String> -DestinationServer <String> -MigratingDatabase <String>
[-NewName <String>] [-SharedPath <String>] [-Detach] [-KillOpenConnections] [-MigrateLogins]
[-PreserveOldUsers] [-AddToAG] [-MigrateDNS] [<CommonParameters>]
Request
Invoke-SQLMigrateDB -DatabasenameSource <String> -DatabasenameDestination <String> [-NewName <String>]
[-SharedPath <String>] [-Detach] [-KillOpenConnections] [-MigrateLogins] [-PreserveOldUsers] [-AddToAG]
[-MigrateDNS] [<CommonParameters>]
DESCRIPTION
This function migrates databases between SQL servers. It supports: - Preserving users on the destination database in case of an overwrite. - Adding databases to Availability Groups. - Migrating DNS aliases to the destination server. - Detaching the source database. - Migrating logins associated with the database to the destination server.
EXAMPLES
EXAMPLE 1
Invoke-SQLMigrateDB -SourceServer "SQLSource" -DestinationServer "SQLDestination" -MigratingDatabase "TestDB" -NewName "TestDB_Copy"
Migrates the "TestDB" database from "SQLSource" to "SQLDestination" with the new name "TestDB_Copy".
EXAMPLE 2
Invoke-SQLMigrateDB -DatabasenameSource "TestDB - SQLSource" -DatabasenameDestination "TestDB_Copy - SQLDestination" -KillOpenConnections -MigrateLogins
Migrates the "TestDB" database from "SQLSource" to "SQLDestination", killing open connections and migrating associated logins.
EXAMPLE 3
Invoke-SQLMigrateDB -SourceServer "SQLSource" -DestinationServer "SQLDestination" -MigratingDatabase "ProdDB" -AddToAG -Detach
Migrates the "ProdDB" database from "SQLSource" to "SQLDestination", adds it to an Availability Group, and detaches the source database.
PARAMETERS
-SourceServer
The SQL server that provides the database for the migration.
Type: String
Parameter Sets: Manual
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DestinationServer
The SQL server to migrate the database to.
Type: String
Parameter Sets: Manual
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-MigratingDatabase
The name of the database to migrate.
Type: String
Parameter Sets: Manual
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DatabasenameSource
The source database and server formatted as "Dbname - Servername".
Type: String
Parameter Sets: Request
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DatabasenameDestination
The destination database and server formatted as "Dbname - Servername".
Type: String
Parameter Sets: Request
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-NewName
The new name for the database on the destination server.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: $MigratingDatabase
Accept pipeline input: False
Accept wildcard characters: False
-SharedPath
The location to save the backup file and exported database users.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Detach
Indicates whether the source database should be detached after migration.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-KillOpenConnections
Indicates whether to kill open connections to the source database.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-MigrateLogins
Indicates whether to migrate logins associated with the database to the destination server.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-PreserveOldUsers
When overwriting an existing database on the destination, recreates users from the original database on the destination after migration.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-AddToAG
Indicates whether to add the database to an Availability Group.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
-MigrateDNS
{{ Fill MigrateDNS Description }}
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
OUTPUTS
NOTES
YYYY-MM-DD - Who - What 2020-06-18 - JT - Initial version 2020-08-26 - JT - New feature: rename database on restore 2020-09-30 - JT - New feature: compatibilty with heat requests input 2020-09-30 - JT - Bugfix: kill connections on destination instead of source 2020-09-30 - JT - Bugfix: Exclude system users on user export 2020-09-30 - JT - Bugfix: import sql logins now working as intended