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
DATA Type Description
nTypeNumeric Backup type: BK_NORMAL (file copy), BK_ZIP (compressed), BK_WIN (Windows Backup)
cSourceCharacter Source path or file specification
cTargetDirCharacter Target directory for the backup
aFilesArray Array of file names to include
TBackup Methods
Method Description
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
DATA Type Description
nTypeNumeric Restore type: RES_NORMAL, RES_ZIP, RES_WIN
lOverwriteLogical Overwrite existing files during restore
TRestore Methods
Method Description
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
BK_NORMAL performs a simple file copy from source to target directory.
BK_ZIP compresses the source files into a single ZIP archive using the specified ZIP file name.
BK_WIN delegates to the Windows NTBackup utility for system-level backups.
Use CreateRestorePoint() before destructive operations to enable system rollback.
The aFiles array can hold individual file names or wildcard specifications.
See Also ← tautoget | tbar →