>* BACKUP.PRG >* Generic backup program > >* Missing: >* More error checking (paths don't exist, etc.) >* comments at end-of-line in function LoadVariables > >* Load options (variables) from text file >LoadVariables("backupoptions.txt", "public") > >define window output from 0,0 to srows() - 1, scols() -1 font "Courier" >activate window output > >* Copy to temp dir >clear >? "Copiando a carpeta temporal" && Copying to temp folder >DosCommand("xcopy " + lcFromFolder + " " + lcTempFolder + "\ /s") > >* Delete excluded files (from temp dir) >local lcDeleteSkeleton >lcExcludeFiles = strtran(lcExcludeFiles, ",", chr(13) + chr(10)) >for i = 1 to memlines(lcExcludeFiles) > lcDeleteSkeleton = alltrim(mline(lcExcludeFiles, i)) > ? "Borrando " + lcDeleteSkeleton + " de carpeta temporal" && Erasing ... from temp folder > DeleteWithSub(lcTempFolder + "\" + lcDeleteSkeleton) >next > >* Backup >? "Comenzando compresión" && Starting compression >lcBackupCommand = strtran(lcBackupCommand, "%1", lcTempFolder) >lcArchiveFileName = lcBaseName + str(year(datetime()),4) >if lnDetailLevel >= 2 > lcArchiveFileName = lcArchiveFileName + "-" + padl(month(datetime()), 2, "0") >endif >if lnDetailLevel >= 3 > lcArchiveFileName = lcArchiveFileName + "-" + padl(day(datetime()), 2, "0") >endif >if lnDetailLevel >= 4 > lcArchiveFileName = lcArchiveFileName + "-" + padl(hour(datetime()), 2, "0") >endif >if lnDetailLevel >= 5 > lcArchiveFileName = lcArchiveFileName + "-" + padl(minute(datetime()), 2, "0") >endif >if lnDetailLevel >= 6 > lcArchiveFileName = lcArchiveFileName + "-" + padl(sec(datetime()), 2, "0") >endif >lcArchiveFileName = lcArchiveFileName + "." + lcExtension >DosCommand(strtran(lcBackupCommand, "%2", lcDestination + "\" + lcArchiveFileName)) > >* Erase temp files >? "Borrando archivos temporales" && Erasing temp files >DosCommand("deltree /y " + lcTempFolder) > >* Copy to additional destination >if not empty(lcDestination2) > ? "Copiando a destino adicional" && Copying to additional folder > copy file (lcDestination + "\" + lcArchiveFileName) to (lcDestination2 + "\" + lcArchiveFileName) >endif > >? "Se finalizó la copia de seguridad." && Backup completed >wait window "Se completó la copia." + chr(13) + "Este mensaje se auto-destruirá en 20 segundos."; > timeout 20 && Backup finished. Closing in 20 seconds. > >FUNCTION DeleteWithSub(tcFullPath) > local lcDir, lcSkeleton > lcDir = justpath(tcFullPath) > lcSkeleton = justfname(tcFullPath) > DelFilesSub(lcDir, lcSkeleton) >ENDFUNC > >FUNCTION DelFilesSub(tcDir, tcSkeleton) > local laFileList(1,1), i, lcDir > for i = 1 to adir(laFileList, tcDir + "\" + tcSkeleton) > erase (tcDir + "\" + laFileList(i, 1)) > next > for i = 1 to adir(laFileList, tcDir + "\*.*", "D") > if laFileList(i, 1) # "." > lcDir = tcDir + "\" + laFileList(i, 1) > DelFilesSub(lcDir, tcSkeleton) > endif > next >ENDFUNC > >FUNCTION LoadVariables(tcFileName, tcDeclarationType) > * Loads variables from a text file > local lcOptions, i, lcLine, lnMemoWidth, lcVariable, lcDeclaration > lnMemoWidth = set("memowidth") > set memowidth to 8192 > lcOptions = FileToStr(tcFileName) > * The use of _mline is much faster than providing a line number to mline(). > * See sample in VFP help file. > _mline = 0 > for i = 1 to memlines(lcOptions) > lcLine = mline(lcOptions, 1, _mline) > if not empty(lcLine) and not inlist(left(lcLine, 1), ";", "[") > * Declare variable public. Private and local don't make sense right now, > * since these would be erased on function exit. The function would have > * to be changed to an #include file this feature. > if not empty(tcDeclarationType) > lcVariable = alltrim(left(lcLine, at("=", lcLine) - 1)) > if not ("(" $ lcVariable or "[" $ lcVariable) && don't declare arrays > lcDeclaration = tcDeclarationType + space(1) + lcVariable > &lcDeclaration > endif > endif > * Assign variable > &lcLine > endif > next > set memowidth to lnMemoWidth >ENDFUNC > >FUNCTION DosCommand(lcCommand) > activate window output > ? "Orden DOS: " + lcCommand && DOS command: > lcCommand = "run " + lcCommand > activate screen > &lcCommand > activate window output >ENDFUNC > >#IF .F. >clear >define window hi from 0,0 to srows()-2, scols()-2 font "Courier" >acti window hi >? "Line 1" >? "Line 2" >acti screen >run del hopefullynonexistentfile.ext >acti window hi >? "Line 3" >#ENDIF >>
>* backupoptions.txt >[COMMENTS] >; Options for automated backup >; Use semicolon and square brackets, at position 1, for comments. >; Don't delete any variables from this file! >; Most variables need values, lcDestination2 can hold the empty string: "" >; Missing: samples for major compression programs. >; The sample is for pacomp.exe, the command-line version of >; PowerArchiver (www.powerarchiver.com; freeware up to version 6.1; version 7 is shareware) > >[OPTIONS START HERE] > >[FOLDERS] >; Location of files to backup >lcFromFolder = "c:\proyectos" > >; Copy files to this location >lcTempFolder = "c:\TempCopy" > >; Main destination >lcDestination = "c:\produccion_varios\backup_interno" > >; Destination for additional copy >lcDestination2 = "\\manaco-ibm\pcp\backupPCP" > > >[OTHER OPTI0NS] >lcExcludeFiles = "*.fxp,*.exe,*.bak,*.tbk,*.tmp,*.chm,*.idx,*.old,produccion\data\*.*" > >; Filename of compressed archive >lcBaseName = "PCP-" >lcExtension = "CAB" > >; Backup command >; %1 is a placeholder for origin folder (i.e., temp folder); filename (*.*) not included >; %2 is a placeholder for destination folder; >; filename (e.g. mydata-2001-04-21.cab) is provided in program. >lcBackupCommand = "c:\archiv~1\pautil\pacomp.exe -a -p %2 %1\*.*" > >; Detail level for filename: 3 = yyyy-mm-dd; 4 adds hours, 5 adds minutes, 6 adds seconds >lnDetailLevel = 5 > >[END OF FILE] >