將地端MSSQL資料庫移轉至aws ec2主機上的MSSQL

 
WinSCP FTP 用存出來的ppk連線上去後就能準備將程式或資料庫檔案給部屬移轉上去


調整默認都切至sudo後的root權限

使用SQL Server Management Studio (SSMS) 或命令行工具,如 sqlcmd,對本地資料庫進行備份,從而創建一個 .bak 文件。

BACKUP DATABASE [YourDatabaseName] TO DISK = 'C:\path_to_backup\YourDatabaseName.bak';




將備份文件傳輸到EC2:


在EC2的SQL Server上還原資料庫:
一旦 .bak 文件在EC2實例上,您可以使用SSMS或 sqlcmd 進行還原。

RESTORE DATABASE [YourDatabaseName] FROM DISK = '/path_on_ec2/YourDatabaseName.bak';


Msg 5133, Level 16, State 1, Server ip-172-31-33-44, Line 1
Directory lookup for the file "E:\IT_Db\BingoDb.mdf" failed with the operating system error 2(The system cannot find the file specified.).
Msg 3156, Level 16, State 3, Server ip-172-31-33-44, Line 1
File 'BingoDb' cannot be restored to 'E:\IT_Db\BingoDb.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Server ip-172-31-33-44, Line 1
Directory lookup for the file "E:\IT_Db\BingoDb_log.ldf" failed with the operating system error 2(The system cannot find the file specified.).
Msg 3156, Level 16, State 3, Server ip-172-31-33-44, Line 1
File 'BingoDb_log' cannot be restored to 'E:\IT_Db\BingoDb_log.ldf'. Use WITH MOVE to identify a valid location for the file.
Msg 3119, Level 16, State 1, Server ip-172-31-33-44, Line 1
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Msg 3013, Level 16, State 1, Server ip-172-31-33-44, Line 1
RESTORE DATABASE is terminating abnormally.

這個錯誤訊息指出,當您從備份中還原資料庫時,SQL Server嘗試將數據文件和日誌文件還原到它們在原始系統上的位置,這些位置在新的系統上可能不存在。特別是,它正在尋找一個在Linux上不存在的 E:\ 磁碟路徑。

為了解決這個問題,需要在還原命令中指定新的文件位置。

可以用 WITH MOVE 選項來完成還原資料庫並移動其文件到新的位置
RESTORE DATABASE BingoDb 
FROM DISK = '/var/tmp/BingoDb.bak'
WITH MOVE 'BingoDb' TO '/var/opt/mssql/data/BingoDb.mdf',
     MOVE 'BingoDb_log' TO '/var/opt/mssql/data/BingoDb_log.ldf';


確定在EC2上的哪個位置您想放置這些文件。
例如,您可能想將它們放在 /var/opt/mssql/data/。





這裡,BingoDb 和 BingoDb_log 是原始資料庫的邏輯文件名。
如果這些不是正確的名稱,您可能需要先運行一個命令來查詢備份中的文件名:

RESTORE FILELISTONLY FROM DISK = '/var/tmp/BingoDb.bak';
將列出備份中的所有文件及其邏輯名稱。



如此一來就成功移轉了







留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題