Skip to content

fbeltrao/sql-filestream-to-storage-migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Server FileStream to Azure Storage

A simple .NET Core 2.1 tool to help you migrate your SQL Server FileStream contents to an Azure SQL database and Azure Blob Storage.

Getting started

  • Visual Studio 2017, .NET Core 2.1
  • Azure SQL Database
  • Azure Blob Storage account
  • Replace the necessary database and storage connection strings in appsettings.json
{
  "source": {
    "sqlServerDatabaseConnectionString": "<-- replace with SQL Server connection string -->",
    "filesStreamInfoCsvFile": "filestream.csv"
  },
  "destination": {
    "azureSqlDatabaseConnectionString": "<-- replace with Azure SQL connection string -->",
    "azureBlobStorageConnectionString": "<-- replace with Azure Blob Storage connection string -->"
  }
}
  • Go to the command line, to the directory where you cloned the repo:
> dotnet restore
> dotnet build src/FileStreamToAzureStorageMigrator.sln
> dotnet run --project src/FileStreamToAzureStorageMigrator/FileStreamToAzureStorageMigrator.csproj
  • It all starts here in 2 easy steps
class Program
    {
        public static IConfiguration Configuration { get; set; }
       
        static async Task Main(string[] args)
        {
            InitializeConfiguration();

            string sourceSqlServerDatabaseConnectionString = Configuration["source:sqlServerDatabaseConnectionString"];
            string destinationAzureSqlDatabaseConnectionString = Configuration["destination:azureSqlDatabaseConnectionString"];
            string destinationAzureBlobStorageConnectionString = Configuration["destination:azureBlobStorageConnectionString"];
            string filesStreamInfoCsvFile = Configuration["source:filesStreamInfoCsvFile"];

            // Step 1: copy the file contents to Blob Storage
            var sqlServerToAzureBlobStorage = new SqlServerToAzureBlobStorage(sourceSqlServerDatabaseConnectionString, destinationAzureBlobStorageConnectionString, filesStreamInfoCsvFile);
            await sqlServerToAzureBlobStorage.CopyDataAsync();

            // Step 2: copy the files metadata (table) to Azure SQL
            var filesMetadataToAzureSql = new CsvFilesMetadataToAzureSql(destinationAzureSqlDatabaseConnectionString, filesStreamInfoCsvFile);
            await filesMetadataToAzureSql.CopyDataAsync();
        }


        /// <summary>
        /// Configuration initialization
        /// </summary>
        private static void InitializeConfiguration()
        {
            var builder = new ConfigurationBuilder()
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddJsonFile("appsettings.json");

            Configuration = builder.Build();
        }


    }
  • You can also adjust:

Contributors

@damirkusar, @DjolePetrovic, @jonathandbailey, @meinradweiss, @fbeltrao and @CarlosSardo

About

Tool to migrate SQL FileStream content to an Azure Storage

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages