Hyper-V - connect a backup drive to a dedicated VM based on serial #

Share

Tagged: 

Viewing 3 reply threads
  • Author
    Posts
    • #1334511
      Dmitrijs G
      Participant
      Post count: 1
      Member Points: 121
      Rank: Level 2

      We have a Hyper-V core with some VM’s on it. Each VM have 3 physical external drive connected to it. VM server on a client-side. The dedicated person supposed to swap all drives daily (MWF, TTS and Monthly) for each VM. So, it’s 3 drives per day
      I have a few scripts
      Enter-PSSession vmhost-name
      Remove-VMHardDiskDrive -VMName “server1 name” -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0
      Remove-VMHardDiskDrive -VMName “server2 name” -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0
      Get-VMScsiController -VMName “server 1 name” | Add-VMHardDiskDrive -DiskNumber 2
      Get-VMScsiController -VMName “server 2 name” | Add-VMHardDiskDrive -DiskNumber 4
      Get-VM -VMName DC | Get-VMHardDiskDrive

      And it’s working fine for one VM. However, if the person who should swap them miss the cable (it’s labelled bu….) or do it wrong drive which should go to for example server 1 actually will to server 2 or opposite. So, it might ok for some time but once a while I have to connect and change controller #

      Goal: write a script which will check all connected backup drives, get their serial numbers and based on the number do connect the drive to one or another VM

      #Connect to VMhost server
      Enter-PSSession vmhost-name
      #remove all existed drives
      Remove-VMHardDiskDrive -VMName “server1 name” -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0
      Remove-VMHardDiskDrive -VMName “server2 name” -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0

      #get all connected drives and assign to $Disks and in my case sort by the manufacturer
      $Disks = Get-PhysicalDisk -CanPool $false -Manufacturer Seagate
      or
      $Disks = Get-WMIObject -class win32_PhysicalMedia

      And then I’m lost .. in theory it might be something like
      $SerialNumber = foreach($Disk in $Disks) {IF ($Disk.SerialNumber -eq ‘ serial number) {[do something here, like connect to VM, maybe: Get-VMScsiController -VMName “server 1 name” | Add-VMHardDiskDrive -DiskNumber 2 }}
      Else
      {check anothr drive}

      In this specific case only 9 drives so it easily can be done by if else

      Again, my original script works fine but it just blindly connects some random drive previously connected to this port to VM and I don’t like it.

      Any suggestions or alternative views will be appreciated.
      PS: yes, I know that I can do NAS as a primary target and backup it after but it’s not my case

      Thanks

      0
    • #1337372
      Michael Pietroforte
      Keymaster
      Post count: 1890
      Member Points: 24,549
      Author of the year 2018
      Rank: Level 4

      I vaguely remember that I had a similar problem a long time ago and at that time there was no real solution. The problem is that some controllers always assign disks randomly and you can’t do anything about it. However, whenever you run into problems that nobody seems to have it is good sign that you are doing something the wrong way. Swapping disks manually every day seems to be something like that. What is the purpose of this procedure?

      0
      • #1337421
        Dmitrijs G
        Participant
        Post count: 1
        Member Points: 121
        Rank: Level 2

        Hi Michael,

        Yes, I agreed that daily HDD disk swap is not perfect and I don’t like it, but in this specific case we are not allowed to send any data outside (so, no remote backup option) and no one wants to spend money on any NAS/SAN, etc..  and the server room in not secure location and client cant/don’t want to use expensive device which someone can just take and walk away. So, the only option we have – a dedicated person who suppose to switch all drives on a daily basis.

        I instructed this (extremely not technical) person to switch ONE drive at the time and in this case, MOSTLY it’s going to the same SCSI controller (in about 75% ) and Remove-VMHardDiskDrive -VMName and  Get-VMScsiController -VMName DC | Add-VMHardDiskDrive works. But I would like to script and forget about it … so, the only constant I have – HDD name and HDD serial#.

        That’s why I would like to make a functional scrip and check all connected backup drives and connect to VM based on serial# (or HDD name)

        Again, any alternative working options (not shared drive, not remote backup to an external location, not backup solutions like Veritas) would be highly appreciated

        Thanks

         

        0
        • #1340059
          Michael Pietroforte
          Keymaster
          Post count: 1890
          Member Points: 24,549
          Author of the year 2018
          Rank: Level 4

          and client cant/don’t want to use expensive device which someone can just take and walk away.

          It seems anyone can take he drives and walk away with them anyway? How about encrypting the devices with BitLocker?

          It also seems your client already chose the most expensive option available, that is, hiring a consultant trying to solve a problem that doesn’t really exist if storage is managed properly. And how much does it cost to manually change the drives daily? There is nothing more expensive than manual work.

          0
        • #1345138
          Dmitrijs G
          Participant
          Post count: 1
          Member Points: 121
          Rank: Level 2

          Hi Michael,

          Yes, you right and I’m 100% agree with you but we have what we have …
          Hyper-V server (one), with a receptionist who should change the backup drives (3 of them) on a daily basis. Encryption is not a primary concern for now (for this specific case).
          After receptionist was properly educated everything is mostly fine (85-90%) but I want to get 100% and curious if someone else was able to do it for this specific scenario
          Thanks

          0
    • #1345158
      David Figueroa
      Participant
      Post count: 12
      Member Points: 2,512
      Rank: Level 3

      What about just checking for volume labels for your removable HDs and keeping an array of which one is used where in the script?

      David F.

      0
    • #1413793
      Dmitrijs G
      Participant
      Post count: 1
      Member Points: 121
      Rank: Level 2

      Just a quick update:

      we scheduled this script and explained the dedicated user on-site how to change the drive(s) (one by one).

      this way everything stays the same until the reboot. For some reason, after reboot drives can be assigned to a different controller # but it takes a few secs to modify the script and it’s a god to go until the next reboot.  Not perfect but if someone has a better solution (I’m sure that someone has) – welcome.

      Thanks

      0
Viewing 3 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account