Game Development Community

dev|Pro Game Development Curriculum

Basic backup script

by Johnathon · 12/26/2007 (10:29 am) · 0 comments

I wrote a simple little windows batch file that would backup my project to my server, however you can use it to copy it to your local hard-drive as well.

net use b: \domainName\UserName [i]passwordHere[/i] /PERSISTENT:no
del /s *.dso

IF EXIST B:\Backups\Torque\MyGame\%date:~0,3% RD B:\Backups\Torque\MyGame\%date:~0,3% /S /Q

xcopy C:\Torque\MyGame\* "B:\Backups\Torque\MyGame\%date:~0,3%\*" /y /s

net use b: /DELETE

and if you want it to backup on your local hardrive

del /s *.dso

IF EXIST C:\Backups\Torque\MyGame\%date:~0,3% RD C:\Backups\Torque\MyGame\%date:~0,3% /S /Q

xcopy C:\Torque\MyGame\* "C:\Backups\Torque\MyGame\%date:~0,3%\*" /y /s

I then use my Windows Scheduler to schedule a backup everynight.

net use b: \domainname\username [i]passwordhere[/i] /PERSISTANT:no
This is where you connect to your server that you want to backup your data to. If you are backing up to your local hard drive you won't need to use this command. /PERSISTANT means that the network connection will not re-connect when you reboot your computer. It connects this one time only.

del /s *.dso
This deletes all of the compiled .dso files in your project prior to backing up your project. You can remove this if you want to back those up as well, but it will decrease the backup time by deleting the dso's first. Less files to copy.

IF EXIST B:\Backups\Torque\MyGame\%date:~0,3% RD B:\Backups\Torque\MyGame\%date:~0,3% /S /Q
next we check if the backup directory already exists. The %date:~0,3% returns the date, trimmed down to just three characters. if you execute this on Sunday, then your directory would be named MyGame\Sun.
if Backups\Torque\myGame\Sun exists, it deletes the directory. /S deletes all the sub folders and files, /Q puts it in quiet mode. If you don't use the /Q then you will be required to enter Y at the command promt to give the RD command permission to delete all files.

xcopy C:\Torque\MyGame\* "C:\Backups\Torque\MyGame\%date:~0,3%\*" /y /s
xcopy copies all the files and folders in your MyGame into your backup folder with the name of the date. the /y suppresses the promt to overwrite files, which we really shouldn't have that problem anyway because we are deleting the directory if it exists. /S copies all the subfolders and files.

net use b: /DELETE
If you are copying to your local harddrive you won't need this command. This will disconnect you from your server once the script has completed.