bup.bat (aka backup batch file)
Below shows off a batch file created for quickly backing up a project folder without needing something like Git as version control. It was created as a quick means to simplify development when rapidly prototyping a project.
The need arose when wanting to code a project and also knowing that we were versioning more than just text. There were images being used and there was no set file structure to easily gitignore. Furthermore we may want to version some of those files as well without thinking too much about it.
To use this batch file one would place it in the project folder they are working in. The backup would be made in the parent folder (the folder above and outside the project folder). This iteration of the batch file also allowed multiple consecutive backups without conflict or issues by appending a version number at the end of the folder name (lines 22-26).
Coupling this code with another batch file that archives each individual folder inside a root folder as zip files allows us to freely edit previous versions before having to finally 'commit' and archive them. While it is originally only made for the Windows OS, the idea may be easily adapted for other systems.
TITLE bup bat backup services
@ECHO OFF
CLS
:: get directory name
FOR %%A IN (.) DO (
SET Newt=%%~nA_bup
)
:: parse date
FOR /F "tokens=1-3 delims=/-" %%A IN ("%DATE%") DO (
SET FirstVal=%%A
SET SecondVal=%%B
SET ThirdVal=%%C
SET Today=%%A%%B%%C
)
:: parse time
SET Now=%Time%
SET Hours=%Now:~0,2%
IF "%Hours:~0,1%"==" " SET Hours=0%TIME:~1,1%
SET Minutes=%Now:~3,2%
SET Stamp=%Hours%%Minutes%
:: check version
SET Version=0
:VersionLoop
SET /A Version=%Version%+1
IF NOT EXIST ../%Newt%/%Today%-%Stamp%-%Version% GOTO Attempt
GOTO VersionLoop
:Attempt
SET Parse=../%Newt%/%Today%-%Stamp%-%Version%
ECHO.
ECHO.
ECHO. ^^oo^^
ECHO. the bup bat attempts to copy a backup!
ECHO. %Parse%
ECHO.
XCOPY "%CD%" "%Parse%" /V /I /E /H
ECHO.