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
System.UnauthorizedAccessException: 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);
string sourcePath = Path.GetDirectoryName(fromDrive);
string newFileName = AppendFileNameWithDate(oldFileName);
string destFile = System.IO.Path.Combine(toDrive, newFileName);
result = 3;
System.IO.File.SetAttributes(fromDrive, FileAttributes.Normal);
System.IO.File.Copy(fromDrive, destFile, true);
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:\";
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: System.IO.File.SetAttributes(fromDrive, FileAttributes.System); It still gives the same error message. It looks like it can't access the path to the file.
I looked at these links but I'm having newbie issues too I think:
http://stackoverflow.com/questions/1267085/vista-uac-trouble-mapping-network-drives[
^]
http://stackoverflow.com/questions/8821410/system-unauthorizedaccessexception-access-to-the-path-denied?lq=1[
^]
http://stackoverflow.com/questions/6402536/access-to-the-path-xxx-is-denied?rq=1[
^]
Thanks,
Michele