views:

39

answers:

2

I want to do a backup of my Projects folder. It mostly contains sub-folders for .NET projects (VS2005, VS08, and VS10).

What should I delete before doing a backup (e.g. TestResults, bin, obj); if there is something I shouldn't delete but should ignore, what might that be; and, most importantly, how best to automate the whole process (I'm thinking batch file or better)?

What gotchas do I need to be aware of?

+3  A: 

I would recommend using source control and backing up the source control repository. If this is just for personal projects, I would recommend either Subversion or Mercurial. They are easy to use, integrate with Windows Explorer, can be setup to ignore certain directories, and provide other well published benefits beyond backup as well.

If the source code repository is backed up, you don't need to backup the projects themselves.

As for additional things you might consider ignoring, you can safely ignore the .user and .suo files, these are just user settings like what files you have open in the project. Depending on your development environment, you can also ignore the .sln files (the solution files). The solution files are easily rebuilt and if you are working in a team environment, it might be easier to have individual solutions.

Brian
Good point. I already use version control (SVN), but I disagree that this makes backups unnecessary - I often keep large files related to projects (but not essential to building them or working with them) in these folders. I don't want these files in SVN, but I'd like to have a backup of them in case I need to restore my computer.
Pat
Out of curiosity, when you say "large", how big are you talking? Perhaps you can just back those files up? Are they part of your project? Or part of the solution? If they are part of the solution, they can be anywhere on the hard drive, including in a Dropbox directory :). For my personal machine, I use Carbonite for backup. It frees me from having to worry about backing up junk files (like bin, obj, and TestResults).
Brian
Ok, well the files aren't extremely large, but sometimes they are 200MB videos or 700MB linux ISOs - they really don't belong in version control.Currently, my Projects folder is about 7GB. When I ran the PowerShell script to delete just the three named folders, it decreased to 5.5GB. If I can save 1.5GB from being backed up unnecessarily, I say that's a good thing (particularly since it's being backed up over the network).
Pat
A: 

Ok, figured out that it's hard to recursively search subfolders and delete those folders matching a pattern using a batch file and cmd. Luckily, PowerShell (which is installed on Windows 7 by default, IIRC) can do it (kudos):

get-childitem C:\Projects\* -include TestResults -recurse | remove-item -recurse -force

That was based off of example 4 of the Remove-Item help entry. It searches the path, recursively, for anything (file or folder) named "TestResults" (could put a wildcard in there if wanted) and pipes the results to the Remove-Item command, which deletes them. To test it out, just remove the pipe to Remove-Item.

How do we remove more than just one folder per statement? Input the list of folders in PowerShell's array syntax:

get-childitem C:\Projects\* -include bin,obj,TestResults -recurse | remove-item -recurse -force

You can run this from the command prompt or similar like so (reference)

powershell.exe -noexit get-childitem C:\Projects\* -include bin,obj,TestResults -recurse | remove-item -recurse

Obvious Disclaimer

Don't use this method if you keep necessary files inside folders or files named bin, obj, etc.

Pat
Honestly, marking a -1 on this one? It answers the original question exactly. If you think the question is bad, mark it, not the answer. And I'm in no way advocating not using version control, so what's the gripe?
Pat