BackupRead function

The BackupRead function can be used to back up a file or directory, including the security information. The function reads data associated with a specified file or directory into a buffer, which can then be written to the backup medium using the WriteFile function.


BOOL BackupRead(
  HANDLE  hFile,
  LPBYTE  lpBuffer,
  DWORD   nNumberOfBytesToRead,
  LPDWORD lpNumberOfBytesRead,
  BOOL    bAbort,
  BOOL    bProcessSecurity,
  LPVOID  *lpContext



Handle to the file or directory to be backed up. To obtain the handle, call the CreateFile function. The SACLs are not read unless the file handle was created with the ACCESS_SYSTEM_SECURITY access right. For more information, see File security and access rights.




Pointer to a buffer that receives the data.




Pointer to a variable that receives the number of bytes read.

If the function returns a nonzero value, and the variable pointed to by lpNumberOfBytesRead is zero, then all the data associated with the file handle has been read.


Indicates whether you have finished using BackupRead on the handle. While you are backing up the file, specify this parameter as FALSE. Once you are done using BackupRead, you must call BackupRead one more time specifying TRUE for this parameter and passing the appropriate lpContext. lpContext must be passed when bAbort is TRUE; all other parameters are ignored.



If bProcessSecurity is TRUE, the ACL data will be backed up.


Pointer to a variable that receives a pointer to an internal data structure used by BackupRead to maintain context information during a backup operation.

You must set the variable pointed to by lpContext to NULL before the first call to BackupRead for the specified file or directory. The function allocates memory for the data structure, and then sets the variable to point to that structure. You must not change lpContext or the variable that it points to between calls to BackupRead.

To release the memory used by the data structure, call BackupRead with the bAbort parameter set to TRUE when the backup operation is complete.

Return value

If the function succeeds, the return value is nonzero.



This function is not intended for use in backing up files encrypted under the Encrypted File System. Use ReadEncryptedFileRaw for that purpose.

If an error occurs while BackupRead is reading data, the calling process can skip the bad data by calling the BackupSeek function.

The file or directory should be restored using the BackupWrite function.


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winbase.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also



Creating a Backup Application