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