TBackup + TRestore

Sources: source/classes/tbackup.prg, source/classes/trestore.prg

Standalone classes

TBackup and TRestore provide data backup and restore functionality supporting three storage types: normal file copy, ZIP compression, and Windows Backup (NTBackup). TBackup handles the backup creation while TRestore manages the restoration process including system restore points.

TBackup Key DATA Members

DATATypeDescription
nTypeNumericBackup type: BK_NORMAL (file copy), BK_ZIP (compressed), BK_WIN (Windows Backup)
cSourceCharacterSource path or file specification
cTargetDirCharacterTarget directory for the backup
aFilesArrayArray of file names to include

TBackup Methods

MethodDescription
New( nType, cSrc, cDst, nLang, cZip, aFiles )Create a new backup object with type, source, target, language, ZIP name, and file list
Execute()Execute the backup operation according to the selected type
MakeZip()Create a ZIP-format backup archive
ExecuteWinBackup()Execute Windows NTBackup operation

TRestore Key DATA Members

DATATypeDescription
nTypeNumericRestore type: RES_NORMAL, RES_ZIP, RES_WIN
lOverwriteLogicalOverwrite existing files during restore

TRestore Methods

MethodDescription
New( nType, cSrc, cDst, nLang, aFiles, lOver )Create a new restore object with type, paths, language, file list, and overwrite flag
Execute()Execute the restore operation
MakeCopy()Restore files by direct file copy
UnZipData()Extract files from a ZIP backup archive
CreateRestorePoint( cDesc )Create a Windows System Restore point with the given description

Commands

DEFINE BACKUP oZip TYPE BK_ZIP ;
   SOURCE cSrc TARGET cDst ZIPNAME cZip FILES aFiles

Example: ZIP Backup and Restore

#include "FiveWin.ch"

function Main()

   local oBackup, oRestore
   local aFiles := { "data1.dbf", "data2.dbf", "data3.dbf" }

   DEFINE BACKUP oBackup TYPE BK_ZIP ;
      SOURCE "C:\Data" TARGET "D:\Backup" ;
      ZIPNAME "backup.zip" FILES aFiles

   if oBackup:Execute()
      MsgInfo( "Backup completed successfully" )
   else
      MsgStop( "Backup failed" )
   endif

   oRestore := TRestore():New( RES_ZIP, "D:\Backup\backup.zip", ;
      "C:\Data\Restored", , aFiles, .T. )

   if oRestore:Execute()
      MsgInfo( "Restore completed successfully" )
   endif

return nil

Notes

Ver También