Friday, April 27, 2012

Simple way to backup code, zip and copy to dropbox

Download 7zip, add it to the path (or just copy the program files to C:\windows\)
Create a .bat file containing
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
echo %mydate%_%mytime%
md C:\temp\%mydate%_%mytime%
robocopy C:\myfoldertobackup\ C:\temp\%mydate%_%mytime%\ *.cs *.js *.aspx *.ascx *.master *.csproj *.sln *.bat *.html *.htm *.css *.sql /s
7z a c:\temp\dropbox\codebackup\ C:\temp\%mydate%_%mytime%
rmdir C:\temp\%mydate%_%mytime%\ /Q /S

Run it.
I would recommend dropbox or something similiar to upload the files to somewhere safe.
Be careful with the rmdir command, make sure you don't delete anything of value.