1

I'm writing a backup program for our new server. I'm an administrator, and I'm learning a lot. The issue is that I can back up a file on the c:\ drive to the c:\ drive, but not for the drives on the SAN, like when I try to backup a file on the T drive (SAN) to the H drive (server). I tried using SetAttributes like Why is access to the path denied? but it basically gives the same error message to try setAttributes as I did when I tried to copy the file. This is a portion of my log:

12/30/2013 2:14:57 PM Successful backup of file C:\test\iceCreamCake_12_30_2013_1414P.docx
12/30/2013 2:14:57 PM exception during backupSystem.UnauthorizedAccessException: Access to the path 'T:\T Drive.vhd' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.SetAttributes(String path, FileAttributes fileAttributes)
   at Bak.BackItUp(String fromDrive, String toDrive) in C:\Users\michele\BackupProj\ServerBackup\ServerBackup\Backup.cs:line 36
12/30/2013 2:14:57 PM exception during backupSystem.UnauthorizedAccessException: Access to the path 'S:\SQL Database.vhd' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.SetAttributes(String path, FileAttributes fileAttributes)
   at Bak.BackItUp(String fromDrive, String toDrive) in C:\Users\michele\BackupProj\ServerBackup\ServerBackup\Backup.cs:line 36

Shouldn't I be able to run my program to do the backup if I'm logged on as Administrator?

Here's part of the code:

    try
    {
        if (System.IO.File.Exists(fromDrive))
        {
            result = 4;
            if (System.IO.Directory.Exists(toDrive))
            {
                string oldFileName = Path.GetFileName(fromDrive); //file name only
                string sourcePath = Path.GetDirectoryName(fromDrive); //path only
                string newFileName = AppendFileNameWithDate(oldFileName); //file name with date added
                string destFile = System.IO.Path.Combine(toDrive, newFileName); //full path of final destination with new file name
                result = 3;

                System.IO.File.SetAttributes(fromDrive, FileAttributes.Normal);
                System.IO.File.Copy(fromDrive, destFile, true);  //copy backupFileName to toDrive, overwrite destination file if it already exists
                if (File.Exists(destFile))
                {
                    Logging.Logging.Instance.Debug("Successful backup of file " + destFile);
                    result = 2;
                }
                else
                {
                    result = -2;
                    Logging.Logging.Instance.Debug("Backup *failure of file " + destFile);
                }

            }
            else
            {
                Logging.Logging.Instance.Debug("to Drive does not exist: " + toDrive);
                result = -1;
            }
        }
        else
        {
            Logging.Logging.Instance.Debug("from Drive does not exist: " + fromDrive);
            result = -1;
        }
    }
    catch (Exception ex)
    {
        Logging.Logging.Instance.Debug("exception during backup" + ex.ToString());
    }

The directory strings are like this:

        string cDrive  = @"C:\backup\2013\iceCreamCake.docx"; 
        string tDrive  =  @"T:\T Drive.vhd";
        string sDrive  =  @"S:\SQL Database.vhd";

        string cDriveToLocation = @"C:\test";
        string tDriveToLocation = @"H:\";
        string sDriveToLocation = @"E:\";
        string vDriveToLocation = @"G:\";

Thanks, Michele

Community
  • 1
  • 1
Michele
  • 3,617
  • 12
  • 47
  • 81
  • is drive `T` a mounted network drive? If so, does it work if you use the UNC path? – Scott Chamberlain Dec 30 '13 at 20:04
  • T drive is on the SAN. I'm pretty sure I'm already using the UNC path. I added some of the code that defines the drive names. – Michele Dec 30 '13 at 20:10
  • 1
    UNC paths start with `\\ServerName\ShareName`. The ones you put in your update are all file paths, what I need to know is how does your computer resolve the `T:\ ` to the SAN instead of a harddrive inside the computer? Is it via network shares, iSCSI, or something else entirely? – Scott Chamberlain Dec 30 '13 at 20:15
  • I'll have to find out from my co-worker after vacation. Thanks for the help! I'm pretty sure it's network shares with ip addresses, etc, but I'm just learning this. The SAN acts like it's directly connected. – Michele Dec 30 '13 at 20:19
  • Test if you do `\\192.168.1.2\SanSahreName\T Drive.vhd` (or whatever the IP and share name is) instead of `T:\T Drive.vhd` if it works. If it does work then you are running in to the same issue as [this question](http://stackoverflow.com/questions/1267085/vista-uac-trouble-mapping-network-drives). – Scott Chamberlain Dec 30 '13 at 20:22
  • @Scott Chamberlain, I talked to my co-worker and he said that the SAN is set up as SAS (not network share or iSCSI), so it is the same as a physically connected hard drive. We were able to open a command window and could xcopy the file on the t-drive to the h-drive, so it's just the code that can't do the copy/recognize the path. I tried changing the filename to @"T:\T_Drive.vhd", and also tried changing the FileAttributes line to: It still give the same error message. It looks like it can't access the path to the file. – Michele Jan 06 '14 at 20:51

1 Answers1

0

Thanks for all your help. I wound up specifically adding (security access to) each of my logins (usxxxxxx and M_CL) to the properties of the files/directories, then editing the privileges to get full control, and also removing all spaces in the file name for the t:\ drive file and the c:\ directories file (it was failing for my M_Cl login but not usxxxx), and it worked for c:\ and t:. We thought the general Users and Administrators file access priviledges would work, but it didn't. The other thing I added was instead of having the complete string for t drive defined with file, I did a path combine like

    string sDrive  =  Path.Combine(@"S:\", @"SQL_Database.vhd");
Michele
  • 3,617
  • 12
  • 47
  • 81