Simple Source Versioning and Backup

Inspired by Casey mentioning his simple custom source control system, and the weird batch file syntax for manipulating strings we saw the other day, I've created a very basic batch file for source control.

You need some type of zip/rar program installed since windows doesn't come with one. I use 7z because its good and free. Place this code in backup.cmd somewhere in your path (eg in the misc folder we've been using in handmade hero). Then just type backup from your projects folder.

It gets the current folder name (eg if you're in w:\projects\handmade it gets the name "handmade") checks the destination folder for a "handmade" folder, creates it if doesn't exist, zips all files and subfolders in the current dir, and creates handmade_YYYYMMDD_HHMMSS.7z in the destination\handmade folder.

Change the DEST_FOLDER to where you want your source versions to go.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@echo off
setlocal

set DEST_PATH=d:\archive

set path=%path%;C:\Program Files (x86)\7-Zip

REM
REM Gets the current folder name, not the full path
REM
for %%* in (.) do set PROJ_NAME=%%~n*

set YEAR=%date:~-4,4%
set MONTH=%date:~-7,2%
set DAY=%date:~-10,2%

set HOUR=%time:~-11,2%
set MIN=%time:~-8,2%
set SEC=%time:~-5,2%

set DEST_FILENAME=%PROJ_NAME%_%YEAR%%MONTH%%DAY%_%HOUR%%MIN%%SEC%

if exist %DEST_PATH%\%PROJ_NAME% goto start

mkdir %DEST_PATH%\%PROJ_NAME%

:start
7z a -r %DEST_PATH%\%PROJ_NAME%\%DEST_FILENAME%.7z *