Converting .bak file format to VHd using Powershell

Welcome Forums General PowerShell Q&A Converting .bak file format to VHd using Powershell

  • This topic has 4 replies, 2 voices, and was last updated 4 weeks ago by
    Participant
    .
Viewing 4 reply threads
  • Author
    Posts
    • #225543
      Participant
      Topics: 1
      Replies: 2
      Points: -2
      Rank: Member

      Hi,

      I have tried using convert-vhd file in power shell scripting to convert a back up file to vhd format but in vain. Can someone please tell me the steps to follow it or any built in function to do the task.

       

      Thanks

    • #225549
      Participant
      Topics: 3
      Replies: 342
      Points: 1,130
      Helping Hand
      Rank: Community Hero

      If you show us what you’ve tried and where it’s not working/errors received, then i’m sure we can help you figure it out.

    • #225561
      Participant
      Topics: 1
      Replies: 2
      Points: -2
      Rank: Member

      If you show us what you’ve tried and where it’s not working/errors received, then i’m sure we can help you figure it out.

      #Get-DbaDiskSpace -ComputerName DESKTOP-RAQK42T
      $input = Read-Host -Prompt ‘Enter Directory Name:’
      $input1 = Read-Host -Prompt ‘Enter Folder Name:’
      New-Item -Path “$input” -Name “$input1” -ItemType “directory”
      echo $input
      echo $input1
      # Variable
      $Server = ‘DESKTOP-RAQK42T’
      $Database = ‘db_airport’
      $BackupFolder = “$input” + “$input1\”
      #$dt = Get-Date -Format yyyy-mm-dd /*Get today date*/
      #$FilePath = “$($BackupFolder)$($Database)_db_$($dt).bak”
      $FilePath = “$($BackupFolder)$($Database).bak”

      #For Backup
      Backup-SqlDatabase -ServerInstance $Server -Database $Database -BackupFile $Filepath

      #After taking a backup (.bak) from SQL server 2017 . I am intending to convert or build an image .vhdx (Hard disk image file). Using this .vhdx file i wan to create a container . I am new to powershell and need little help. Thanks

    • #225570
      Participant
      Topics: 3
      Replies: 342
      Points: 1,130
      Helping Hand
      Rank: Community Hero

      So this works to create your backup fine, I assume. Now you are wanting a container with the contents of the backup? Maybe i’m misunderstanding, but wouldn’t you just want to spin up a SQL container, and then restore your backup?

      https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash

      https://hub.docker.com/_/microsoft-mssql-server

      Perhaps you can provide clarity on what exactly you’re intending to do with the VHD. Since it’s a SQL backup file, I imagine you’re wanting to either access the data within or verify it’s integrity.

    • #225876
      Participant
      Topics: 1
      Replies: 2
      Points: -2
      Rank: Member

      So this works to create your backup fine, I assume. Now you are wanting a container with the contents of the backup? Maybe i’m misunderstanding, but wouldn’t you just want to spin up a SQL container, and then restore your backup?

      https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash

      https://hub.docker.com/_/microsoft-mssql-server

      Perhaps you can provide clarity on what exactly you’re intending to do with the VHD. Since it’s a SQL backup file, I imagine you’re wanting to either access the data within or verify it’s integrity.

      For clarity:

      Thanks for your valuable feedback. the link you provided is used to create the container. but I am stuck to build an image from the .bak file.

      I have multiple backups (.bak). I want to build an image for all backups and after using this image file I want to create a windocks container that includes (container name, port, and password). so that I assign the container to a different department in the organization. The steps are : (taking backups > build image>create a windocks container)

      I want to automate all these steps using PowerShell.

       

      • This reply was modified 4 weeks ago by Mian50.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.