• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows [Tool] Simple to use backup batch script

Mick

Member
Do you backup your projects? I read about people loosing their projects (for various reasons) on the GMC too often. It's very important to make backups, people often learn this too late though. It's really frustrating to re-do something you have put much time, energy or effort in, even if it's "just" a day's worth of work.

The more experienced programmers here know all this already and probably use version control for their bigger projects. Version control can be a bit hard to get into, so if you're not ready for that yet, have some kind of backup routine! :) I made a batch script to make this process very easy.

How to use
To use the backup script, all you need to do is define the destination folder in the script and store a copy of the script in your project folder (or any folder you want to backup). To create a backup you simply double-click the the batch file. You can create a shortcut for the batch file on the desktop or somewhere else.

The backup folder will have the same name as the source folder plus a timestamp ("project" -> "project-20180421-084659"). You don't need to edit the batch file even if you move your project or rename it, only if you wish to change the destination folder need you edit it.

Compress backup
You can also optionally tell the script to compress the backup to a zip file using 7-zip. For this you would need 7z.exe and 7z.dll in your Windows folder (or any folder in PATH)

Download
http://gamephase.net/files/linked/backup.zip
(Extract the zip file)

The script itself
Code:
@echo off

:: SETTINGS START *****************
:: Source folder, leave empty to copy folder where batch file is located
set "source="
:: Destination folder, this should be a "parent" folder, backups will be created in this folder
set "destination=C:\ProjectBackups"
:: Create zip-file of backup using 7-zip? You need 7z.exe and 7z.dll in the Windows folder for this to work. Get 7-zip here: https://www.7-zip.org/
set "compress=false"
:: Wait for key press before closing command prompt?
set "waitforkey=false"
:: ********************************

echo @@@@    @@@    @@@   @   @  @   @  @@@@   @@
echo @   @  @   @  @   @  @  @   @   @  @   @  @@
echo @@@@   @@@@@  @      @@@    @   @  @   @  @@
echo @   @  @   @  @   @  @  @   @   @  @@@@ 
echo @@@@   @   @   @@@   @   @   @@@   @      @@

:: Set source to folder where batch file is run if source is not already set above (%0 is batch file)
if not defined source set source=%~dp0

:: Add trailing backslash to source if needed
if not "%source:~-1%"=="\" set source=%source%\

:: Get name of directory where batch file is run
for %%a in (%source%) do for %%b in ("%%~dpa\.") do set "foldername=%%~nxb"

:: Remove possible double quotes from source and destination
set source=%source:"=%
set destination=%destination:"=%

:: Remove trailing backslash from source and destination
if "%source:~-1%"=="\" set source=%source:~0,-1%
if "%destination:~-1%"=="\" set destination=%destination:~0,-1%

:: Don't run backup if source and destination are the same
if /I %source%==%destination% (
    echo Destination can't be the same as source, bailing out...
    goto endofscript
)

:: Get datetime in a good format
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,8%-%datetime:~8,6%

:: Copy directory to destination
xcopy /E /I /Y "%source%" "%destination%\%foldername%-%datetime%"

:: Delete batch file from destination
if exist "%destination%\%foldername%-%datetime%\backup.bat" (
    del "%destination%\%foldername%-%datetime%\backup.bat"
)

:: Compress backup if compress=true
if "%compress%" == "true" (
    :: Create zip
    7z a "%destination%\%foldername%-%datetime%.zip" "%destination%\%foldername%-%datetime%"
    :: Delete Backup folder
    rmdir /S /Q "%destination%\%foldername%-%datetime%"
)

echo @@@@    @@@    @@@   @@@@@  @@
echo @   @  @   @  @   @  @      @@
echo @   @  @   @  @   @  @@@@   @@
echo @   @  @   @  @   @  @   
echo @@@@    @@@   @   @  @@@@@  @@

:endofscript
:: Wait for key if waitforkey=true
if "%waitforkey%" == "true" (
    pause
)
 
Top