How to clear Azure Storage Emulator Data from command line?
Asked Answered
S

3

43

My solution is using Azure Emulator. I would like to clear the Azure Storage Emulator Blobs, Queues and Tables without having to perform manual actions. I need to be able to do it from command line, preferably PowerShell.

Server Explorer in Visual Studio 2015, Azure-node:

enter image description here

AzureStorageEmulator.exe help returns the following commands:

  • AzureStorageEmulator.exe init: Initialize the emulator database and configuration.
  • AzureStorageEmulator.exe start: Start the emulator.
  • AzureStorageEmulator.exe stop: Stop the emulator.
  • AzureStorageEmulator.exe status: Get current emulator status.
  • AzureStorageEmulator.exe clear: Delete all data in the emulator.
  • AzureStorageEmulator.exe help [command]: Show general or command-specific help.

However when trying out "clear" the following is returned:

The following services have been succesfully cleared of user data: None

Skinny answered 12/7, 2016 at 12:47 Comment(0)
S
82
cd C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
.\AzureStorageEmulator.exe clear all
Skinny answered 12/7, 2016 at 13:59 Comment(4)
this hangs for me! anyone have any ideas how to do this manually?Specialize
The docs for the Storage Emulator command line tool are at: learn.microsoft.com/en-us/azure/storage/common/…Federal
@JohnNicholas - Stop the emulator. Then delete the AzureStorageEmulatorDbXXX.mdf / ldf files in your windows home directory.Groundsel
For people suspecting a hang: it took a long time to run for me, several minutes.Poikilothermic
A
18

Visual Studio 2022 and Azurite

  • it will not use SQL Server like Legacy Storage Simulator and all the related data is stored as large JSON files in the following folder.

%userprofile%\AppData\Local\Temp\Azurite

or maybe

%userprofile%\AppData\Local\.vstools\Azurite

Azurite Emulator default location

  • you will see Azurite services starting up in Visual Studio Service Dependencies Window when you open VS with any project that needs this enter image description here
  • Azure Storage Explorer Will automatically connect to this new emulator VIA REST-API and if you using Legacy Emulator and new emulator at the same time you are working with different data sets
  • it seems that Azurite currently has no explicit stop and clear command (3.14.3) and if you cannot delete these folders, just close both Visual Studio and Storage Explorer and try again.
  • see also related note on official note in azurite github (link)

Note. Delete above files and folders and restart Azurite to clean up Azurite. It will remove all data stored in Azurite!!


check always the Output -> Service Dependencies to find the correct location. Recently the location is changed to the following folder

%USERPROFILE%\AppData\Local\.vstools\azurite

Visual Studio 2019 and deprecated Azure Storage Emulator

Running "AzureStorageEmulator.exe clear all" & "init" command usually hangs (or may take too much time)

solution: you can go to user folder (%userprofile%) usually in the following address and delete existing AzureStorageEmulatorDb510.mdf and ldf files.(last suffix 510 stands for version 5.10 of emulator)

C:\Users\[YOUR_USER] or %userprofile%

if you can not delete them you because they are locked, stop Azure Storage Emulator by running AzureStorageEmulator.exe stop and try again or simply by shutting it down from its icon in system tray

Autacoid answered 29/11, 2021 at 15:22 Comment(0)
W
3

An alternative approach if you are using Azurite & VS2022+ is to use VSCode Durable Functions Monitor extension to delete the hub in the emulator.

I found Purge and Clean operations (from VSCode ext.) failed against Azurite both when I ran from VS2022 or using docker. They work for me when I am using real Azure storage. This eliminates the annoyance of having to quit VS before you can delete the files.

Deleting the hub in VSCode Durable Functions Monitor is by far the quickest way I have found so far to reset everything before another debug run.

Wellhead answered 5/1, 2022 at 7:53 Comment(1)
Those purge methods are useless.Saval

© 2022 - 2024 — McMap. All rights reserved.