[英]How to import a dumb file to Azure DB on mySQL Server, the dump resides in the blob. How can I dynamically access the blob file
My power shell code, downloads the dump file from azure storage to my local drive. 我的power shell代码,将转储文件从azure存储下载到我的本地驱动器。 Get-AzureStorageBlobContent -Container $storagecontainername -Blob $backupfilename -Destination $restorefilename
Import happens using the dump file in the local drive. 使用本地驱动器中的转储文件进行导入。 get-content $restorefilename | &"$mysqlpath" -h $servername -u $username -p $password $database
I am looking to replace this $restorefilename
with the blob file directly. 我希望直接用blob文件替换这个$restorefilename
。
There is no built-in cmdlet for this. 没有内置的cmdlet。
You can use some .net method in powershell to directly download the blob files as string. 您可以在powershell中使用一些.net方法直接将blob文件下载为字符串。
Note: if the blob storage is public, you can just directly use it's url. 注意:如果blob存储是公共的,您可以直接使用它的url。 if the blob storage is private, you should generate a SAS token for the blob. 如果blob存储是私有的,则应为blob生成SAS令牌。
sample code as below for a public blob: 公共blob的示例代码如下:
$client = New-Object System.Net.WebClient
$client.DownloadString("https://xxx.blob.core.windows.net/f22/t1.txt")
Test result as below: 测试结果如下:
so in your case, you can write something like below: 所以在你的情况下,你可以写下面的东西:
$client = New-Object System.Net.WebClient
$restorefilename = $client.DownloadString("https://xxx.blob.core.windows.net/f22/t1.txt")
$restorefilename | &"$mysqlpath" -h $servername -u $username -p $password $database
And if your blob is private, you can follow the screenshot below to generate a sas url for downloading: 如果您的blob是私有的,您可以按照下面的屏幕截图生成一个用于下载的sas URL:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.