Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup Clarion Project BAT files
@REM This will backup the File Extensions listed below for ROBOCOPY to a subfolder
@REM then zip using PowerShell to a file named: ProjName_Date_Time.ZIP
@REM I place this BAT file in the Project folder named: _Bak_and_Zip_ProjBane.bat
@REM This backs up to a sub folder named _Bak_ under the project, some times I place this folder elsewhere
@REM This saves the CLW that allows for doing a code compare
@REM -----------------------------------------------------------------
@echo off
for /f %%I in ('wmic os get localdatetime ^|find "20"') do set dt=%%I
REM dt format is now YYYYMMDDhhmmss...
REM dt format is now 01234567890123
echo %dt%
REM YMD only --> set dt=%dt:~4,2%-%dt:~2,2%-%dt:~0,4%
REM ------------- Backup Folder Settings -----------------
SET SrcFld=.
SET BakFld=_Bak_\Bak_Last
SET BakZip=_Bak_\ProjName_%dt:~0,8%_%dt:~8,6%.ZIP
echo Backup %SrcFld%
echo Backup to %BakFld%
echo Zip into %BakZip%
REM ------------------------------------------------------
REM pause
@echo off
MD %BakFld%
@IF NOT EXIST %BakFld% THEN PAUSE
ROBOcopy %SrcFld% %BakFld% ^
*.clw *.inc *.app *.ap~ *.bpp *.dct ^
*.cwproj *.sln *.manifest *.red *.lib ^
*.cur *.ico *.png *.gif ^
*.dctx *.txa *.txd ^
*.bat *.ini *.msbuild *.txt *.h ^
/MT /R:2 /W:5 /PURGE ^
/TEE /LOG+:%BakFld%\_RoboCopy.LOG
rem IF ERRORLEVEL == 1 PAUSE
REM /MT=Multi Thread, /Retry /W=Wait Error, /TEE=Counsel and Log File, /LOG=Log File
REM /PURGE :: delete dest files/dirs that no longer exist in source.
echo+
echo Finished Copy to %BakFld%
echo --------------------------------
echo powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
rem pause
powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
IF ERRORLEVEL == 1 PAUSE
REM UltraEdit makes backup for BAT file named .Bat.Bak
DEL %0.bak
DEL Bak_*.bat.bak
@REM This backs up all APPs to a folder on another drive
@REM For this I also use One_App_Bak_2bats.bat to do a specific APP.
@REM ----------------------------------------------------
@echo off
SET App2Bak=Tier2_ALL
for /f %%I in ('wmic os get localdatetime ^|find "20"') do set dt=%%I
Set DATE_TIME=%dt:~0,8%_%dt:~8,6%
ECHO ------------- Backup Folder Settings -----------------
SET SrcFld=C:\C11APPS\EisTrsTier2
SET PreFx=%App2Bak%
SET BakFld=D:\C11_BAKUP\EisTier2_BAK\_Bak_\_Bak_%PreFx%
SET BakZip=D:\C11_BAKUP\EisTier2_BAK\_Bak_\%PreFx%_%DATE_TIME%.ZIP
echo Backup %SrcFld%
echo Backup to %BakFld%
echo Zip into %BakZip%
REM pause
ECHO ------------------------------------------------------
rem pause
@echo off
REM Delete the files from the current backup folder so old wood is removed
del /Q %BakFld%\*.*
MD %BakFld%
@IF NOT EXIST %BakFld% THEN PAUSE
echo on
ROBOcopy %SrcFld% %BakFld% ^
payroll.dct *.clw *.inc *.APP *.AP~ *.BPP ^
*.sln *.cwproj *.RED *.BAT *.MSBUILD *.manifest *.cur *.ico *.INI *.TXT SSEC*.TPS ^
/MT /R:1 /W:2 /TEE /LOG:%BakFld%\_RoboCopy.LOG
@IF ERRORLEVEL 8 ECHO Did RoboCopy have trouble, error level = %ERRORLEVEL%
@IF ERRORLEVEL 8 PAUSE
@echo off
REM Can then see files touched with DIR *.CLW /AA
ATTRIB -A %SrcFld%\*.CLW
ATTRIB -A %SrcFld%\*.APP
REM Pass on Command Line %1 %2. IDEA could have Call Back BAT to copy more files
REM REM On the command line pass additional files to copy
REM goto :NoMrFiles
REM :CmdLnFile
REM IF (%1)==() GOTO :NoMrFiles
REM COPY %SrcFld%\%1 %BakFld%
REM SHIFT
REM GOTO :CmdLnFile
REM :NoMrFiles
REM /MT=Multi Thread, /Retry /W=Wait Error, /TEE=Counsel and Log File, /LOG=Log File
REM /PURGE :: delete dest files/dirs that no longer exist in source.
REM decided to not use PURGE and to manually remove obsolete files from Bak_Last folder
echo+
echo Finished Copy to %BakFld%
echo --------------------------------
echo powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
rem pause
powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
rem @pause
:EndBat
DEL %0.bak
Echo Window Preview EXE Orphans can be cleaned out
del %SrcFld%\WinPreview????????-????-*.exe
Here I have 1 BAT file per APP to backup using 2nd BAT.
So there are 2 BAT files here to split out.
The #1 would exist for each APP so I can backuo just that one.
The #1 calls the #2 to do the real work which depends on the SET App2Bak=Pr03
#1 --------------- Save this as: BakZip_Pr03.BAT ---------------
echo off
SET App2Bak=Pr03
CALL BakZip1TierPrApp.BAT
@IF ErrorLevel 1 Echo Error!!! %ErrorLevel% & pause
Pause
del %0.bak
#2 --------------- Save this as: BakZip1TierPrApp.BAT ---------------
@echo off
IF not (%App2Bak%)==() GOTO :GotApp
ECHO CALLer must SET App2Bak=
PAUSE
GOTO :EndBat
:GotApp
for /f %%I in ('wmic os get localdatetime ^|find "20"') do set dt=%%I
Set DATE_TIME=%dt:~0,8%_%dt:~8,6%
ECHO ------------- Backup Folder Settings -----------------
SET SrcFld=C:\C11APPS\EisTrsTier2
SET PreFx=%App2Bak%
SET BakFld=D:\C11_BAKUP\EisTier2_BAK\_Bak_\_Bak_%PreFx%
SET BakZip=D:\C11_BAKUP\EisTier2_BAK\_Bak_\%PreFx%_%DATE_TIME%.ZIP
echo Backup %SrcFld%
echo Backup to %BakFld%
echo Zip into %BakZip%
REM pause
ECHO ------------------------------------------------------
rem pause
@echo off
REM Delete the files from the current backup folder so old wood is removed
del /Q %BakFld%\*.*
MD %BakFld%
@IF NOT EXIST %BakFld% THEN PAUSE
ROBOcopy %SrcFld% %BakFld% payroll.dct ^
%PreFx%*.clw %PreFx%*.inc %PreFx%*.app ^
%PreFx%*.cwproj %PreFx%*.sln %PreFx%*.manifest ^
%PreFx%*.bat %PreFx%*.ini %PreFx%*.txt %1 %2 %3 %4 %5 %6 %7 %8 %9 ^
/MT /R:1 /W:2 /TEE /LOG:%BakFld%\_RoboCopy.LOG
IF ERRORLEVEL 8 ECHO Did RoboCopy have trouble, error level = %ERRORLEVEL%
IF ERRORLEVEL 8 PAUSE
REM Pass on Command Line %1 %2. IDEA could have Call Back BAT to copy more files
REM REM On the command line pass additional files to copy
REM goto :NoMrFiles
REM :CmdLnFile
REM IF (%1)==() GOTO :NoMrFiles
REM COPY %SrcFld%\%1 %BakFld%
REM SHIFT
REM GOTO :CmdLnFile
REM :NoMrFiles
REM /MT=Multi Thread, /Retry /W=Wait Error, /TEE=Counsel and Log File, /LOG=Log File
REM /PURGE :: delete dest files/dirs that no longer exist in source.
REM decided to not use PURGE and to manually remove obsolete files from Bak_Last folder
echo+
echo Finished Copy to %BakFld%
echo --------------------------------
echo powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
rem pause
powershell Compress-Archive -Path %BakFld%\* -DestinationPath %BakZip%
rem @pause
:EndBat
DEL %0.bak
@REM Posted by Fullham in ClarionLive Weekly Webinar 1/20/21
@REM One of my "backup" methods is to use a CMD file from the desktop to make a 7zip file which gets the date/time
@REM and project name as part of its name. Feel free to modify this batch file:
@REM -----------------------------------------------------------------
@ECHO OFF
@REM Copy SM API source files to BackupSrc Folder and then use 7zip to back them up
SET SrcDrive=D:
SET SrcDir=\SMGR1202-C11\APINWB
SET Prefix=API
SET BakDir=D:\Backups
%SrcDrive%
CD %SrcDir%
IF NOT EXIST %SrcDir%\BackupSrc MKDIR %srcDir%\BackupSrc
IF NOT EXIST BackupSrc\LibSrc MKDIR BackupSrc\LibSrc
COPY *.app BackupSrc\*.*
COPY *.cwproj BackupSrc\*.*
COPY *.DCT BackupSrc\*.*
COPY *.sln BackupSrc\*.*
COPY LIBSRC\*.* BackupSrc\LIBSRC\*.*
REM GET System Date and time in YYYY-MM-DD-HHMM format
REM Substring designations: Variable:~Offset,Length%
SET ymdaytm=%date:~10,4%-%date:~4,2%-%date:~7,2%-%time:~0,2%%time:~3,2%
SET arch=%BakDir%\%Prefix%-%ymdaytm%.zip
C:
CD "\Program Files\7-Zip"
@ECHO ON
7z a -tzip "%arch%" "%SrcDrive%%SrcDir%\BackupSrc\*"
@ECHO OFF
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment