2022年2月23日 星期三

Azrue | 備分Storage account資料到地端On-Premises

這邊介紹簡單備分Azure Storage Account到地端的步驟,主要針對想要把Storage Account資料全部下載到地端需求的人來介紹。


步驟一:下載Azcopy


備份資料最主要就是用到Azcopy命令,去微軟網站就可以下載到,有Linux, Windows, Mac的版本。


步驟二:新增Storage Account的使用者權限


這邊你可以在Resource group或是Storage Account新增使用者權限,角色給予Storage Blob Data Contributor,如下圖,備份過程失敗通常都是權限問題。


步驟三:Azcopy login


Windows打開Powershell,其他就是打開Terminal,切換到Azcopy的目錄下,輸入azcopy login,這時候會提示到微軟網站去做認證並輸入認證碼,登入的帳號當然就是選步驟二你給予權限的帳號。
# ./azcopy login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code SPDY98TKY to authenticate.

INFO: Logging in under the "Common" tenant. This will log the account in under its home tenant.
INFO: If you plan to use AzCopy with a B2B account (where the account's home tenant is separate from the tenant of the target storage account), please sign in under the target tenant with --tenant-id
INFO: Login succeeded.


步驟三:產生Shared access signature


如下圖,先點選要備份的Storage account,然後在SAS的Allowed resource types三個都打勾後,最後再點選Generate SAS and connecting string.


如下圖產生後的URL下面步驟會用,Blob和File service是我們會用到的

步驟四:備份Blob Storage


如果只要備份Blob其實是不用走步驟三,但為了查一下網址所以還是先跑步驟三,azcopy備份到地端的用法如下,storageaccount就是你自己在Azure命名的名稱,目的端看你是在哪個環境備份,Windows可以輸入D:\backup,我這邊範例是Linux,有問題的畫也有Log可以查看。
azcopy copy "https://storageaccount.blob.core.windows.net/" "Destination" --recursive
# ./azcopy copy "https://police.blob.core.windows.net/" "/nas02/Police" --recursive
INFO: Scanning...
INFO: Authenticating to source using Azure AD
INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support

Job 05d8986b-4319-4d46-648f-2f3e708fe191 has started
Log file is located at: /root/.azcopy/05d8986b-4319-4d46-648f-2f3e708fe191.log

99.3 %, 5 Done, 0 Failed, 1 Pending, 0 Skipped, 6 Total, 2-sec Throughput (Mb/s): 7.664


Job 05d8986b-4319-4d46-648f-2f3e708fe191 summary
Elapsed Time (Minutes): 0.0667
Number of File Transfers: 6
Number of Folder Property Transfers: 0
Total Number of Transfers: 6
Number of Transfers Completed: 6
Number of Transfers Failed: 0
Number of Transfers Skipped: 0
TotalBytesTransferred: 1929728
Final Job Status: Completed


步驟五:備份File Shares


備份File Shares就需要用到步驟三的連結,指令用法如下。
azcopy copy "SAS產生的Filse Share連結" "Destination" --recursive
# ./azcopy copy "https://police.file.core.windows.net/?sv=2020-08-04&ss=bfqt&srt=sco&sp=rwdlacupitfx&se=2022-02-23T17:06:26Z&st=2022-02-23T09:06:26Z&spr=https&sig=4w8mGvpaY23gZGojg7xSyWZE%2Fh5LHM7XLvInNiqSs9Q%3D" "/nas02/Police/FileShare" --recursive
INFO: Scanning...
INFO: Any empty folders will be processed, because source and destination both support folders

Job 0296c6d5-429a-284c-754b-7eff099d6731 has started
Log file is located at: /root/.azcopy/0296c6d5-429a-284c-754b-7eff099d6731.log

INFO: Trying 4 concurrent connections (initial starting point)
INFO: Trying 16 concurrent connections (seeking optimum)
INFO: Trying 4 concurrent connections (backing off)
96.7 %, 268 Done, 0 Failed, 3 Pending, 0 Skipped, 271 Total, 2-sec Throughput (Mb/s): 132.334


Job 0296c6d5-429a-284c-754b-7eff099d6731 summary
Elapsed Time (Minutes): 0.2667
Number of File Transfers: 153
Number of Folder Property Transfers: 118
Total Number of Transfers: 271
Number of Transfers Completed: 271
Number of Transfers Failed: 0
Number of Transfers Skipped: 0
TotalBytesTransferred: 254405499
Final Job Status: Completed



如果想知道更進階用法請參考這邊的說明文件

沒有留言: