----^--->
/\

//\\
//The\
/Sy
stem\
////
Guard
\

In the mount of the LORD it shall be seen. Genesis 22:14

Snapshot (compressed cmd for FREE Version)

Booming Or Fuming? | MasterCatalog | ntlib (FREE) | NTCmdLib | MtCmds | Scripts | Almost Free | TheGuardBook | Help

 

Snapshot .cmdHelp OutLine .cmdSrc .cmd :HEADER :PRELIM :SETUP :WORK :VERIFY :NOTIFY :FINISH :ERROR
Click an area from the above list to jump directly to that section.

:=============================================================================
:-> TSG_Snapshot.cmd 2004.03.28 (create a backup whenever a file changes)
:=============================================================================
: File Name.............TSG_Snapshot.cmd
: File Location.........PlaceLocalPathHere
: Coded By..............TheSystemGuard
: Service Date..........2004.03.28
: Last Revised By.......TheSystemGuard
: Revision Date.........2004.03.28
:=============================================================================
:>>> DO NOT CHANGE THE SPACING OR FORMATTING OF ANYTHING ABOVE THIS LINE!! <<<
@((ECHO OFF)&(SETLOCAL ENABLEEXTENSIONS)&(IF "%1"=="" GOTO :Syntax))
ECHO:"%1"|%systemroot%\system32\FindStr.exe /i "\/? -? \/help -help">NUL&&GOTO :Help
((IF NOT DEFINED # CALL %cmdlib% /i /q 2>NUL>NUL)&(IF NOT DEFINED # CALL NTCmdLib.cmd /i /q 2>NUL>NUL)&(IF NOT DEFINED # CALL MtCmds.cmd /i /q 2>NUL>NUL)&(IF NOT DEFINED # CALL ntlib.cmd /i /q 2>NUL>NUL))
IF NOT DEFINED #libName ((SET "ErrorMsg=Unable to Initialize Command Library.")&(GOTO :ERROR)) ELSE (IF /I NOT "%#libname%"=="NTCmdLib" (IF /I NOT "%#libname%"=="MtCmds" (IF /I NOT "%#libname%"=="ntlib" ((SET "ErrorMsg=Command Library %#libName% not recognized.")&(GOTO :ERROR)))))
((SET "ScriptName=TSG_Snapshot Advanced 2004.03.28")&(SET "ReportTitle=TSG_Snapshot running on %COMPUTERNAME% as [%USERNAME%]")&(SET FileToSave=)&(SET SafePlace=)&(SET Interval=)&(SET SecondsToWait=)&(SET ErrorMsg=)&(SET WindowTitle=)&(SET Snapshot_Count=0)&(SET Snapshot_Passes=0)&(SET Snapshots_Taken=0)&(SET Snapshots_Missed=0))
SET "FileToSave=%1"
%!IND%FileToSave ((SET "ErrorMsg=No file specified.")&(%!GEr%))
%!INX%%FileToSave% ((SET "ErrorMsg=File %FileToSave% does not exist")&(%!GEr%))
SET "FileDisplayName=%~nx1"
SET "SafePlace=%2"
%!IND%SafePlace SET "SafePlace=C:\!Snapshot"
%!INX%%SafePlace%%!S%MD %SafePlace%
%.ifErr%((SET ErrorMsg=Unable to create folder %SafePlace%)&(%!GEr%))
%!IN%"%3"=="" SET/A Interval=%3
IF 1%Interval% LSS 11 SET/A Interval=5
%!G%WORK
:Help
((ECHO: ^^ =========================================================================)&(ECHO: /~\ Snapshot Advanced Release 2004.03.28 ^(Free from TheSystemGuard.com!^))&(ECHO:/cmd\ =========================================================================)&(ECHO:)&(ECHO: Create a snapshot backup when a file changes.)&(ECHO:_______________________________________________________________________________)&(ECHO:)&(ECHO:TSG_Snapshot [/?] [drive:][path]FileToProtect [SafeLocation] [Interval])&(ECHO:)&(ECHO:SWITCHES:)&(ECHO: /? Display this help.)&(ECHO:)&(ECHO:PARAMETERS: Default values are shown in {}'s)&(ECHO: FileToProtect A SINGLE file to protect ^(no wildcards!^))&(ECHO: [SafeLocation] Folder to hold snapshots {C:\!Snapshot})&(ECHO: [Interval] Minutes between file checks {5})&(ECHO:)&(ECHO:ERRORLEVELS:)&(ECHO: 0 = Normal or expected finish.)&(ECHO: 1 = Help screen was displayed.)&(ECHO: 2 = Script exited with a known error. See %%ErrorMsg%% for details.)&(ECHO: 3 = Script exited with an unspecified error.)&(ECHO:)&(ECHO:NOTES:)&(ECHO: The SafeLocation folder will be created if necessary.)&(ECHO:)&(ECHO: Interval time DOES NOT include time spent comparing and copying files.)&(ECHO: The Interval counter is reset at the beginning of each waiting period.)&(ECHO: Actual wait time is NOT PRECISE, and can overshoot by several seconds,)&(ECHO: depending upon system load ^(see the .Wait command^).)&(ECHO:)&(ECHO: If any optional parameter is used, all optional parameters to it's left MUST)&(ECHO: be specified. For example, to use Interval, also specify SafeLocation.)&(ECHO:))
((ECHO: All Advanced Scripts ^(those prefixed with "TSG_"^) from TheSystemGuard.com)&(ECHO: REQUIRE the Advanced NT/2K/XP/K3 Command Library ^(ntlib.cmd^). This library)&(ECHO: provides over 200 resources for writing, testing and maintaining RELIABLE)&(ECHO: shell scripts using only the native commands and utilities that are present in)&(ECHO: ALL NT-based operating systems. Write a script ONCE using ntlib.cmd and your)&(ECHO: script will perform CONSISTENTLY under Windows NT4, 2000, XP and Server 2003!)&(ECHO: Request your FREE copy of the Advanced Library today at ^(http://ntlib.com^).)&(ECHO:)&(ECHO:*******************************************************************************)&(ECHO:)&(ECHO: Snapshot Expert uses the enlarged "Expert Command Library" ^(NTCmdLib.cmd^),)&(ECHO: enabling many additional command line switches and parameters. All Expert)&(ECHO: Scripts ^(those prefixed with "!"^) are complete, ready-to-run applications)&(ECHO: that do not require any commands or utilities not already present in every)&(ECHO: NT/2K/XP/K3 install. !Scripts are distributed uncompressed and are fully)&(ECHO: commented so you can quickly fashion them to your specific requirements.)&(ECHO:)&(ECHO: An example of what you're missing ^(from the help screen of !Snapshot.cmd^):)&(ECHO:)&(ECHO:SWITCHES: Default values are shown in {}'s)&(ECHO: /C Compact window during run ^(size restored at Final Report^). {off})&(ECHO: /FP FullPath ^(use the full path of FileToProtect in window title^) {name.ext})&(ECHO: /NV NoVisual ^(don't change console colors to reflect operating status^) {on})&(ECHO: /P Pause ^(pause console after Final Report^) {off})&(ECHO: /WF WaitforFile ^(bypass error if FileToProtect does not exist^) {off})&(ECHO:))
((ECHO:PARAMETERS: Default values are shown in {}'s)&(ECHO: [Warning_Trigger] Consecutive missed snapshots before warning. {1})&(ECHO: [Error_Trigger] Consecutive missed snapshots before error. {2})&(ECHO: [MaxSnaps] Maximum snapshots to take before stopping. {25})&(ECHO: [MaxTime] Maximum time ^(in minutes^) to wait. {480} ^(8 hours^))&(ECHO:)&(ECHO: !Snapshot.cmd provides a color-coded, self-adjusting console window to enable)&(ECHO: at-a-glance monitoring of all running snapshots while using minimum desktop)&(ECHO: real estate. We also include a ".reg" file to allow right-click access to the)&(ECHO: !Snapshot script from inside Windows Explorer. Just highlight any file, then)&(ECHO: right-click, and select "Protect with !Snapshot".)&(ECHO:)&(ECHO: Both the Expert Command Library and !Snapshot are "Almost Free" at $9 or less!)&(ECHO: See ^(http://TheSystemGuard.com/AlmostFree.asp^) for The Almost Free Price List.)&(ECHO:)&(ECHO: The VERY LATEST KNOWLEDGE pertaining to the Windows NT/2K/XP/K3 command line)&(ECHO: can be found at TheSystemGuard.com. Check the MasterCatalog often for a)&(ECHO: continually growing collection ^(http://TheSystemGuard.com/MasterCatalog.asp^).)&(ECHO: You'll learn to build RELIABLE and MAINTAINABLE shell scripts that will always)&(ECHO: perform CONSISTENTLY on every Windows NT-based system right out of the box!)&(ECHO: Don't forget our FREE KnowledgeLetter at ^(http://BoomingOrFuming.com^) and...)&(ECHO:)&(ECHO: Congratulations On Your Decision To RISE ABOVE THE REST!!!))
:Syntax
((ECHO:_______________________________________________________________________________)&(ECHO:)&(ECHO:TSG_Snapshot [/?] [drive:][path]FileToProtect [SafeLocation] [Interval])&(ECHO:)&(MD 2>NUL)&(GOTO :EOF))
:WORK
((TITLE Snapshot [%FileDisplayName%])&(SET/A SecondsToWait=Interval*60)&(SET #LogDate=)&(SET #LogTime=))
:Bgn_Loop
((TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%} ^(comparing^))&(%!S%(@ECHO:N|%.Comp%"%FileToSave%" "%SafePlace%\Latest.%~nx1")&&%!G%Current))
:MakeSnap
((%!ID%#LogDate SET "PreviousLogDate=%#LogDate%")&(%!ID%#LogTime SET "PreviousLogTime=%#LogTime%")&(%!S%((%.GetLogDate%)&(%.GetLogTime%))))
IF 1%Snapshot_Passes% LSS 11 ((%!S%REN "%SafePlace%\Latest.%~nx1" "%SafePlace%\Before.%#LogDate%-%#LogTime%.%~nx1")%!E%(%!S%REN "%SafePlace%\Latest.%~nx1" "%PreviousLogDate%-%PreviousLogTime%.%~nx1"))
((TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%} ^(copying^))&(%!S%COPY %FileToSave% %SafePlace%\Latest.%~nx1))
%.ifOK%((SET/A Snapshots_Taken+=1,NoError_Sequence+=1 ,Error_Sequence=0,Skip_Sequence=0)&(%!S0%)%!E%(SET/A Snapshots_Missed+=1,Error_Sequence+=1,NoError_Sequence=0,Skip_Sequence=0)&(%!S1%))
((%.ifOK%((%.dtEcho% Snapshot taken. {%Snapshots_Taken%})%!E%(%.dtEcho% Snapshot missed. {%Error_Sequence%})))&(TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%})&(%!G%Wait))
:Current
((SET/A Skip_Sequence+=1)&(%.dtEcho% Snapshot current. {^%%Skip_Sequence^%%})&(%!G%Wait))
:Wait
SET/A Snapshot_Passes+=1,Total_Wait_Minutes+=Interval
((IF 1%Snapshots_Taken% GEQ 13%!G%End_Loop)&(IF 1%Total_Wait_Minutes% GEQ 16%!G%End_Loop)&(TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%} ^(waiting^))&(%.dtEcho% Waiting %Interval% minute^(s^)...)&(%.Wait%%SecondsToWait%)&(%!G%Bgn_Loop))
:End_Loop
SET/A Total_Wait_Minutes-=1
((TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%} ^(notify^))&(%.ReportHeader%)&(ECHO: Source File: %#TAB% %~dpnx1)&(ECHO: Destination Folder: %#TAB% %SafePlace%)&(ECHO: Snapshots Taken: %#TAB% %Snapshots_Taken%)&(ECHO: Total Minutes Waited: %#TAB% %Total_Wait_Minutes% minute^(s^))&(TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%} ^(finish^)))
((IF 1%Snapshot_Passes% GTR 10 (%.ReportFooter%))&(%!S0%)&(%!GE%))
:ERROR
((TITLE Snapshot [%FileDisplayName%] {%Snapshots_Taken%} ^(error^))&(%.ErrEcho%)&(%!ID%ErrorMsg ((%.ErrEcho% %ErrorMsg%)&(%.ErrEcho%)&(%!S2%)&(%!GE%)%!E%(%.ErrEcho%Script exited with an unspecified error)&(%.ErrEcho%)&(%!S3%)&(%!GE%))))
:EOF

Snapshot .cmdHelp OutLine .cmdSrc .cmd :HEADER :PRELIM :SETUP :WORK :VERIFY :NOTIFY :FINISH :ERROR
/\
//\\
//
The\
/Sy
stem\
////
Guard
\
COME ON UP WITH US!
and
Congratulations On Your Decision
to
RISE ABOVE
THE REST!

^
/
!\
/LIB\

TheSystemGuard.com [Revised: 2007-03-29]
Copyright © 1995-2007, JWC
Computer Communications,
All Rights Reserved, Worldwide.
 Disclaimer       Privacy       About Us       More


Communication Is Business!

We Master It With Knowledge!

^
/
.\
/M^C\