43

I would like to use 7-zip to backup a directory, but I would like it to exclude all directories named ".svn" (anywhere in the source tree). Does anybody know if this is possible and in that case how?

6 Answers 6

36

To exclude all .svn directories you need to add the -xr!?svn\* switch

For example the following will create a backup of the C:\Project\To\Backup directory excluding any folders that satisfy ?svn:

"C:\Program Files\7-Zip\7z.exe" a -r -tzip -y -xr!?svn\* Project.zip C:\Project\To\Backup\*
6
  • Thanks ManiacD, but I can't get this to work -xr!?svn* gives me an error and if I try -xr!.svn* it still won't exclude .svn Aug 23, 2009 at 12:03
  • you need a backslash after ?svn for it to work that signifies to exclude everything underneath the .svn directory. -xr!?svn\*
    – ManiacD
    Aug 23, 2009 at 14:04
  • Don't worry I had heaps of problems initially getting it work as well. The 7-zip exclude switch -x (-xr recurse directory) with ! excludes filenames based on a wildcard search. Without the backslash it is trying to exclude filenames that match ?svn* ie. asvn.log with the \* at the end mean don't include anything underneath a directory matching ?svn
    – ManiacD
    Aug 23, 2009 at 14:18
  • For details on how to use wildcards have a look at the help file shipped with 7-Zip. Helped me to fix a similar task a few days ago. 7-Zip uses wildcards a bit ... different ;)
    – släcker
    Aug 23, 2009 at 15:22
  • 3
    And if you stumbled here looking for general folder exclusion, note that the ? is to match "period-svn" (.svn), so to to skip everything in folder SkipMe you would use -xr!SkipMe\*
    – drzaus
    Oct 16, 2013 at 21:15
13

Instead of using 7-Zip to exclude the .svn (or potentially _svn) folders, I would recommend using the svn export command (use svn.exe from SlikSVN) to export the working copy to a temporary folder:

svn export C:\Path\To\WC C:\Backup\Staging

Then use 7-Zip as follows:

7z.exe a "C:\Parth\To\Archive" "C:\Backup\Staging\*" -bd t7z -v2g -r

Then delete the staging folder.

This is what I do to backup my local working copies.

1
  • Thanks for the export tip. Available on TortoiseSVN menu too. Jul 28, 2010 at 23:00
12

You can exclude files with 7zip using a list of files or directories:

/path/to7Zip/7z a -bd f:/backup/backup_2009-08-23_daily.zip home \
          '-xr@\path\to\backup_daily_exclude.lst'

The exclude file looks like:

home\Photos\iPod*
home\dhltd\*
BlogMatrix\Sparks\db\*.archive
home\eclipse\*
.svn

The key is the -xr and in particular the "r" which indicates apply the exclude list recursively, to each level of the directory. You may want to use 2 exclude file lists one for absolute and one for recursive exclusions. The above is from a bash script that runs in cygwin.

4

When I used

"C:\Program Files\7-Zip\7z.exe" a -r -ttar -xr!?git\* aufs2-util.tar aufs2-util\*

it ended up adding the .git directory which I didn't want, changing it to

"C:\Program Files\7-Zip\7z.exe" a -r -ttar -xr!?git\ aufs2-util.tar aufs2-util\*

got the desired result.

3

When I used

7z a "D:\codebase\w.7z" "D:\codebase\Edison\otm\Webapp" -t7z -mx0 -xr!WEB-INF\*

the WEB-INF directory was not excluded. Adding an asterisk before the dir name

7z a "D:\codebase\w.7z" "D:\codebase\Edison\otm\Webapp" -t7z -mx0 -xr!*WEB-INF\*

Got the desired result.

1
  • asterisk part is the most important. This should get more upvotes.
    – Valerio
    Oct 5, 2018 at 14:55
0

For me, I was trying to backup a bunch of maven code directories and wanted to exclude any directory named "target":

"C:\Program Files\7-Zip\7z.exe" a -r -tzip -y -xr!*\target\* site.zip C:\code\site\

Relevant exclude parameter was -xr!*\target\*.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .