I have a bunch of different Subversion repositories where I store documents. Occasionally I'll place some unversioned files in these directories while working on something. Today I needed to take a snapshot of the contents of my hard drive but I didn't want to keep all the hidden .svn directories. Here's what worked for me.
First, to clarify - what I wanted to do was take a snapshot of all files in my working directories (even the non-versioned ones). In some cases, the SVN server was no longer around (for one reason or another) so this was really about taking the files on my hard drive and archiving them somewhere (but removing the .svn hidden files and directories).
I use cygwin on my Windows box because I love the power that Unix command line gives me. Unfortunately, I hadn't installed the man package in cygwin, so I used Google to find a tar man page. It told me there is an exclude-file option (-X) so I did the following:
This creates a text file, called exclude.txt that has one line for every hidden .svn directory. The reason I cut the first two characters out of the grep is because tar (for whatever reason) wouldn't exclude a directory named "./blah/.svn" but it would exclude a directory named "blah/.svn".
Once I had the exclude file, then I ran the tar command:
Hope it helps someone else...
An even better solution is to use the same exclude file no matter what the repos layout is. Just include the directory with and without a trailing slash.
svnexclude.txt:
*/.svn
*/.svn/*
Command:
tar czvfX archive.tgz svnexclude.txt dir1/* dir2/*
Wow Mike, thanks for the tip – I’ll have to remember that next time I need to do a backup…
Kill the SVN directories prior to tar.
#!/bin/bash
cd YOURDIR; for i in `find . -name .svn`; do rm -rf $i; done; cd ..
tar -czf yourdir.tar.gz YOURDIR
Sorry, thought that was for a “one time” removal.