Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Methods Directory/File.Copy throw DeviceNotReadyException when using GLOBALROOT source path. #456

Closed
VladimirK69 opened this issue Jun 8, 2018 · 10 comments
Assignees
Labels
Milestone

Comments

@VladimirK69
Copy link

I'm trying to copy files from SQL Server data folder into another folder where I can work with them by using Shadowcopy (AlphaVSS). I made simple project by example from VSS
` string source_file = @"c:\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\ALLTYPES_log.ldf";
string backup_root = @"D:\Backups";
string backup_path = Path.Combine(backup_root, Path.GetFileName(source_file));

  // Initialize the shadow copy subsystem.
  using (VssBackup vss = new VssBackup())
  {
     vss.Setup(Path.GetPathRoot(source_file));
     string snap_path = vss.GetSnapshotPath(source_file);
  
     // Here we use the AlphaFS library to make the copy.
     Alphaleonis.Win32.Filesystem.File.Copy(snap_path, backup_path);
  }

First error was with '?' in snap_path "\\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy9\\Program Files\\Microsoft SQL Server\\MSSQL12.MSSQL2014\\MSSQL\\ALLTYPES_log.ldf", but I disabled that in Path.Helpers.cs with switch (num)
{
case 34: // " (quote)
case 60: // < (less than)
case 62: // > (greater than)
case 124: // | (pipe)
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.Illegal_Characters_In_Path, (char) num), "path");

           default:
              // 32: space
              if (num >= 32) // && (!checkAdditional || num != WildcardQuestionChar && num != WildcardStarMatchAllChar))
                 continue;

              goto case 34;
        }

`
Now I have "Alphaleonis.Win32.Filesystem.DeviceNotReadyException: '(21) The device is not ready: [GLOBALROOT]'" in Alphaleonis.Win32.Filesystem.File.Copy(snap_path, backup_path) but it suppose to be fixed in 2.2.1. I downloaded today AlphaFS-develop, tried 2.2.2 but still have error. Am I doing something wrong or error in AlphaFS?

@Yomodo Yomodo added the Bug 🪲 label Jun 8, 2018
@Yomodo
Copy link
Collaborator

Yomodo commented Jun 8, 2018

You're not doing anything wrong, it is a new bug related to GLOBALROOT.

@Yomodo Yomodo changed the title The device is not ready: [GLOBALROOT] Method File.Copy throws The device is not ready when using GLOBALROOT source path. Jun 8, 2018
@Yomodo Yomodo changed the title Method File.Copy throws The device is not ready when using GLOBALROOT source path. Method File.Copy throws DeviceNotReadyException when using GLOBALROOT source path. Jun 8, 2018
@VladimirK69
Copy link
Author

You asked me to confirm "Could you verify that delayUntilReboot is false?" - it is false in File.Copy.cs 761. But I guess you already reproduced.

@Yomodo
Copy link
Collaborator

Yomodo commented Jun 9, 2018

Yeah, sorry about that, post that message while debugging when I did not mean to. :)
The exception also applies when using Directory.Copy, so a fix is on its way.

@Yomodo Yomodo changed the title Method File.Copy throws DeviceNotReadyException when using GLOBALROOT source path. Methods Directory/File.Copy throws DeviceNotReadyException when using GLOBALROOT source path. Jun 9, 2018
@Yomodo Yomodo changed the title Methods Directory/File.Copy throws DeviceNotReadyException when using GLOBALROOT source path. Methods Directory/File.Copy throw DeviceNotReadyException when using GLOBALROOT source path. Jun 9, 2018
@Yomodo Yomodo added this to the Release 2.2 milestone Jun 9, 2018
@Yomodo Yomodo self-assigned this Jun 9, 2018
@Yomodo
Copy link
Collaborator

Yomodo commented Jun 9, 2018

Could you try branch #456 so see if the issue is resolved?

@Yomodo Yomodo closed this as completed in 9ea257d Jun 9, 2018
Yomodo added a commit that referenced this issue Jun 9, 2018
@Yomodo Yomodo reopened this Jun 9, 2018
@VladimirK69
Copy link
Author

It solved GLOBALROOT issue, but now I have "System.IO.FileNotFoundException: '\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy4\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\ALLTYPES_log.ldf'" at Directory.ExistsDrive.cs line 94. And this is snap_path returned by
string snap_path = vss.GetSnapshotPath(source_file);
""\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy4\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\ALLTYPES_log.ldf"". How to check that VSS really created snapshot and it is where path points?

@Yomodo
Copy link
Collaborator

Yomodo commented Jun 9, 2018

var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(globalRoot);
Console.WriteLine("Input GlobalRoot Path: [{0}]\n", dirInfo.FullName);
if (!dirInfo.Exists)
UnitTestAssert.InconclusiveBecauseFileNotFound("No volume shadow copy found.");

You should be able to use AlphaFS methods Directory/File.Exists to check if it exists.

@VladimirK69
Copy link
Author

VladimirK69 commented Jun 9, 2018

I'm bit confused. Code at the start of topic from VSS 1.40 src\Samples\VssBackup, Snapshot.cs and VssBackup.cs used. Snapshot created before
Alphaleonis.Win32.Filesystem.File.Copy(snap_path, backup_path);
and I can see it with NirSoft ShadowCopyView https://www.nirsoft.net/utils/shadow_copy_view.html
For example snap_path

"\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\ALLTYPES_log.ldf"

and I can see

"\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6"

in that tool, can copy file from snapshot

"c:\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\ALLTYPES_log.ldf" to "d:\Backups"

with that tool, but AlphaFS fails with "System.IO.FileNotFoundException:

'\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy6\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\ALLTYPES_log.ldf'"

I'm not familiar with Shadowcopy service, but if I understand it right VSS creates snapshot "HarddiskVolumeShadowCopy6" and through that snapshot AlphaFS going to copy file? Is that correct? Is it AlphaFS fails or is there already suppose to be file "ALLTYPES_log.ldf" in "HarddiskVolumeShadowCopy6" before AlphaFS will be able to copy it?

@Yomodo
Copy link
Collaborator

Yomodo commented Jun 9, 2018

Yes, AlphaFS expects the directory/file to exist in HarddiskVolumeShadowCopy6.

@VladimirK69
Copy link
Author

Last issue was on my side: "DATA" folder missing from source path. After changing to openFileDialog with "ValidateNames=false" to get file path everything works (I checked path side by side to figure).

Thanks for help and amazing work. It saved me from making the same through kernel mode drivers.

@Yomodo
Copy link
Collaborator

Yomodo commented Jun 9, 2018

Glad to hear! Thanks for the bug.

@Yomodo Yomodo closed this as completed Jun 9, 2018
Yomodo added a commit that referenced this issue Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants