Copy a file while it is open

  • Thread starter Thread starter Samuel
  • Start date Start date
S

Samuel

I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a way
of doing that? (it seems that backup programs are doing just that)

Thank you,
Samuel
 
Samuel said:
I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a way
of doing that? (it seems that backup programs are doing just that)


Basically you can do that using the classes in the 'System.IO' namespace,
except for files that are opened exclusively for reading by other processes.
 
Thank you for your reply,

And what can be done in the case of a file being exclusively opened by
another process?

Do backup program copy these files as well (I think they do)

Samuel
 
Backup programs use various methods to attempt to backup files that are locked. In the
case of databases (i.e. Exchange) an agent can be used to connect to the database and read
the info that way. In the case of other types of files, you could try to create shadow
copies of the files you think will be in use when doing backups. Never done it, but it
sounds like an interesting thing to try. Sometimes files that are in use are not able to
be backed up.
 
Thank you for your reply,

And what can be done in the case of a file being exclusively opened by
another process?

Do backup program copy these files as well (I think they do)

Samuel

Not sure if this is possble --- and if it is, i'm not sure it's entirely
wise. Backing up an open file has a number of considerations. It is up to
the discretion of the application how frequently to write the file to disk.
Thus you might back up an incomplete file that might appear later to be
corrupt
 
Look at the Shadow Copy API. This API set was designed for this
idea. You will have one issue, kernel exclusive control for read/
write access will always block user space requests for read. If a
process has NOT allowed a user process to read shared, while another
process has exclusive read/write will be an issue. How Microsoft gets
past this, is some what inconsistent. NTBackup for example even has
trouble reading SOME things.
 
Thanks for your reply

1. How can I find out whether a file is opened
2. If a file is open how can know whether the current state of the file is
complete? if that's possible at all

Regards,
Samuel
 
Back
Top