在啟動 SQL Server 遷移助理(SSMA)主控台應用程式之前,先建立腳本檔案。 如有需要,建立變數值檔案與伺服器連線檔案。
腳本檔案分為三個區段:
config:設定主控台應用程式的設定參數。servers:設定來源伺服器與目標伺服器定義。 你也可以把這些定義放在獨立的伺服器連線檔案裡。script-commands執行 SSMA 工作流程指令。
每個章節在以下章節中有詳細說明:
設定存取控制台設定
主控台腳本檔案顯示腳本的設定。
如果你在設定節點指定任何元素,你就要為所有腳本指令設定全域設定。 要覆寫全域設定,請在該 script-command 區段的每個指令中設定這些設定元素。
你可以設定以下選項:
輸出視窗提供者:如果你將屬性設
suppress-messages為true,主控台不會顯示指令專屬訊息。 屬性為:destination: 指定輸出是列印為檔案還是stdout。 這個屬性是false預設的。file-name:檔案的路徑(可選)。suppress-messages: 在控制台上抑制訊息。 這個屬性是false預設的。
範例:
<output-providers> <output-window suppress-messages="<true/false>" (optional) destination="<file/stdout>" (optional) file-name="<file-name>" (optional) /> </output-providers>或
<...All commands...> <output-window suppress-messages="<true/false>" (optional) destination="<file/stdout>" (optional) file-name="<file-name>" (optional) /> </...All commands...>資料遷移連線提供者:指定使用哪個來源或目標伺服器進行資料遷移。
source-use-last-used表示最後使用的來源伺服器用於資料遷移。 同樣地,target-use-last-used表示資料遷移使用了最後一次使用的目標伺服器。 使用source-serverortarget-server屬性來指定伺服器。你只能使用以下其中一個屬性:
-
source-use-last-used="true"(預設)或source-server="source_servername" -
target-use-last-used="true"(預設)或target-server="target_servername"
範例:
<output-providers> <data-migration-connection source-use-last-used="true" target-server="target_1"/> </output-providers>或
<migrate-data> <data-migration-connection source-server="source_1" target-use-last-used="true"/> </migrate-data>-
使用者輸入彈出視窗:當主控台從資料庫載入物件時,處理錯誤。 使用者提供輸入模式,若有錯誤,主控台會依照使用者指示進行。
模式包括:
-
ask-user:提示使用者繼續(yes)或發生錯誤(no)。 -
error: 主控台顯示錯誤並停止執行。 -
continue: 控制台繼續執行。
預設模式為
error。範例:
<output-providers> <user-input-popup mode="<ask-user/continue/error>"/> </output-providers>或
<!-- Connect to target database --> <connect-target-database server="target_0"> <user-input-popup mode="<ask-user/continue/error>"/> </connect-target-database>-
Reconnect Provider:如果連線失敗,會設定重新連線的設定。 同時為來源伺服器和目標伺服器設定此選項。
重新連線模式為:
-
reconnect-to-last-used-server:如果連線未啟用,它最多嘗試重新連接上一次使用的伺服器五次。 -
generate-an-error:如果連線未啟用,系統會產生錯誤。
預設模式為
generate-an-error。範例:
<output-providers> <reconnect-manager on-source-reconnect="<reconnect-to-last-used-server/generate-an-error>" on-target-reconnect="<reconnect-to-last-used-server/generate-an-error>"/> </output-providers>或
<!--synchronization--> <synchronize-target> <reconnect-manager on-target-reconnect="reconnect-to-last-used-server"/> </synchronize-target>或
<!--data migration--> <migrate-data server="target_0"> <reconnect-manager on-source-reconnect="reconnect-to-last-used-server" on-target-reconnect="generate-an-error"/> </migrate-data>-
轉換器覆寫提供者:使用此設定來處理目標元基上已存在的物件。 可能的動作包括:
-
error: 主控台顯示錯誤並停止執行。 -
overwrite覆寫現有物件值。 這個動作是預設的。 -
skip: 主控台會跳過資料庫中已存在的物件。 -
ask-user: 提示使用者輸入(yes或no)。
範例:
<output-providers> <object-overwrite action="<error|skip|overwrite|ask-user>"/> </output-providers>或
<convert-schema object-name="ssma.TT1"> <object-overwrite action="<error|skip|overwrite|ask-user>"/> </convert-schema>-
失敗的前置條件提供者:使用此設定處理處理指令所需的前置條件。 根據預設,
strict-mode是false。 如果你設定為true,系統會產生一個例外,表示未符合前置條件。範例:
<output-providers> <prerequisites strict-mode="<true|false>"/> </output-providers>停止操作:在操作中途停止操作,請使用 Ctrl+C 鍵盤快捷鍵。 SSMA 主控台會等待操作完成後終止主控台執行。
如果你想立即停止執行,請再次按下 Ctrl+C 鍵盤快捷鍵,這樣 SSMA 主控台應用程式會突然終止。
進度提供者:通知每個主控台指令的進度。 預設會停用此設定。 進度報告屬性包含:
offevery-1%every-2%every-5%every-10%every-20%
範例:
<output-providers> <progress-reporting enable="<true|false>" (optional) report-messages="<true|false>" (optional) report-progress="every-1%|every-2%|every-5%|every-10%|every-20%|off" (optional)/> </output-providers>或
<...All commands...> <progress-reporting enable="<true|false>" (optional) report-messages="<true|false>" (optional) report-progress="every-1%|every-2%|every-5%|every-10%|every-20%|off" (optional)/> </...All commands...>日誌詳細程度:設定日誌詳細程度。 此設定對應於介面中的 「所有類別 」選項。 預設情況下,對數的冗長程度為
error。記錄器層級選項包括:
-
fatal-error:只記錄致命錯誤訊息。 -
error: 僅記錄錯誤與致命錯誤訊息。 -
warning: 記錄除錯訊息與資訊訊息外的所有層級。 -
info記錄除錯訊息外的所有層級。 -
debug:記錄所有層級的訊息。
備註
SSMA 會記錄任何層級的強制訊息。
範例:
<output-providers> <log-verbosity level="fatal-error/error/warning/info/debug"/> </output-providers>或
<...All commands...> <log-verbosity level="fatal-error/error/warning/info/debug"/> </...All commands...>-
覆寫加密密碼:若
true,伺服器連線檔案的伺服器定義區段或腳本檔會使用明文密碼覆蓋儲存在受保護儲存空間中的加密密碼(若存在)。 若未指定明文密碼,系統會提示使用者輸入密碼。會產生兩種情況:
若覆寫選項為
false,搜尋順序為 受保護儲存 > 腳本檔案 > 伺服器連接檔案 > 提示 使用者。若覆寫選項為
true,搜尋順序為 腳本檔案 > 伺服器連接檔案 > 提示詞使用者。
範例:
<output-providers> <encrypted-password override="<true/false>"/> </output-providers>
無法設定的選項為:
-
最大重連次數:當已建立的連線因網路故障而逾時或中斷時,伺服器需要重新連線。 主控台允許最多
5五次重試以重新連線。 這些重試後,主控台會自動執行重新連線。 自動重新連線功能減少了重執行腳本的麻煩。
伺服器連線參數
你可以在腳本檔或伺服器連線檔中定義伺服器連線參數。 欲了解更多資訊,請參閱 建立伺服器連線檔案。
腳本指令
指令檔包含一系列 XML 格式的移轉工作流程命令。 SSMA 主控台應用程式依照腳本檔案中出現的指令順序處理遷移。
例如,Access 資料庫中特定資料表的典型資料遷移遵循以下階層結構:資料庫 > 資料表。
當腳本檔案中的所有指令成功執行後,SSMA 主控台應用程式會退出並將控制權還給使用者。 腳本檔案的內容大致是靜態的,變數資訊會包含在 建立變數值檔案 中,或在腳本檔案內的變數值獨立區塊中。
範例:
<!--Sample of script file commands -->
<ssma-script-file>
<script-commands>
<create-new-project project-folder="$project_folder$"
project-name="$project_name$"
overwrite-if-exists="true"/>
<connect-source-database server="source_2"/>
<save-project/>
<close-project/>
</script-commands>
</ssma-script-file>
產品目錄中的 Sample Console Scripts 資料夾提供範本,包含三個腳本檔案(用於執行各種情境)、一個變數值檔案,以及一個伺服器連線檔案:
AssessmentReportGenerationSample.xmlConversionAndDataMigrationSample.xmlVariableValueFileSample.xmlServersConnectionFileSample.xml
你可以在更改參數以保持相關性後執行範本。
完整腳本指令清單,請參見 執行 SSMA 主控台。
指令檔驗證
你可以用資料夾裡A2SSConsoleScriptSchema.xsd的 schema 定義檔Schemas來驗證你的腳本檔案。