Home » Questions » Computers [ Ask a new question ]

How do I use 7-zip to backup files, but exclude some directories

How do I use 7-zip to backup files, but exclude some directories

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?

Asked by: Guest | Views: 129
Total answers/comments: 3
Guest [Entry]

"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\*"
Guest [Entry]

"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."
Guest [Entry]

"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\*."
"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\*."