1
我試圖使用Transfer Class將數據庫從一臺服務器複製到另一臺服務器。我無法成功傳輸列的默認值。其他的一切(數據,限制等)都沒有問題。從備份恢復不是一種選擇。傳輸對象默認值不傳輸
try{Import-Module SQLPS -DisableNameChecking}
catch{write-error "Could not import SQLPS powershell module."}
$SourceInstanceName = 'localhost'
$DestInstanceName = xxx'
$CopyDBName = 'xxx'
$SourceDBName = 'xxx'
$source = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $SourceInstanceName
$mySrvConn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$mySrvConn.ServerInstance=$DestInstanceName
$mySrvConn.LoginSecure = $false
$mySrvConn.Login = "xxx"
$mySrvConn.Password = "xxx"
$dest = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server($mySrvConn)
#create SMO handle to your database
$SourceDB = $source.Databases[$SourceDBName]
#database to hold the copy of your source database
$CopyDB = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Database -ArgumentList $dest , $CopyDBName
$CopyDB.Create()
#Use SMO Transfer Class by specifying source database
#you can specify properties you want either brought over or excluded, when the copy happens
$ObjTransfer = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Transfer -ArgumentList $SourceDB
$ObjTransfer.DestinationDatabase = $CopyDBName
$ObjTransfer.DestinationServer = $DestInstanceName
$ObjTransfer.DestinationLoginSecure = $false # can enable once all servers are on domain
$ObjTransfer.DestinationLogin = 'xxxxxx'
$ObjTransfer.DestinationPassword = 'xxxxxx'
#if you wish to just generate the copy script
#just script out the transfer
#$ObjTransfer.ScriptTransfer()
#When you are ready to bring the data and schema over,
#you can use the TransferData method
$ObjTransfer.CopyAllDatabaseTriggers = $true
$ObjTransfer.CopyAllDefaults = $true
$ObjTransfer.CopyAllFullTextCatalogs = $true
$ObjTransfer.CopyAllFullTextStopLists = $true
$ObjTransfer.CopyAllObjects = $true
$ObjTransfer.CopyAllPartitionFunctions = $true
$ObjTransfer.CopyAllPartitionSchemes = $true
$ObjTransfer.CopyAllPlanGuides = $true
$ObjTransfer.CopyAllRoles = $true
$ObjTransfer.CopyAllRules = $true
$ObjTransfer.CopyAllSchemas = $true
$ObjTransfer.CopyAllSearchPropertyLists = $true
$ObjTransfer.CopyAllSequences = $true
$ObjTransfer.CopyAllSqlAssemblies = $true
$ObjTransfer.CopyAllStoredProcedures = $true
$ObjTransfer.CopyAllSynonyms = $true
$ObjTransfer.CopyAllTables = $true
$ObjTransfer.CopyAllUserDefinedAggregates = $true
$ObjTransfer.CopyAllUserDefinedDataTypes = $true
$ObjTransfer.CopyAllUserDefinedFunctions = $true
$ObjTransfer.CopyAllUserDefinedTableTypes = $true
$ObjTransfer.CopyAllUserDefinedTypes = $true
$ObjTransfer.CopyAllViews = $true
$ObjTransfer.CopyAllXmlSchemaCollections = $true
$ObjTransfer.CopyData = $true
$ObjTransfer.CopySchema = $true
$ObjTransfer.DestinationTranslateChar = $true
$ObjTransfer.DropDestinationObjectsFirst = $true
$ObjTransfer.PrefetchObjects = $true
$ObjTransfer.PreserveDbo = $true
$ObjTransfer.PreserveLogins = $true
$ObjTransfer.SourceTranslateChar = $true
$ObjTransfer.UseDestinationTransaction = $true
$ObjTransfer.Options.WithDependencies = $true
$ObjTransfer.Options.ContinueScriptingOnError = $true
$ObjTransfer.TransferData()