5

I'd like to make a .7z archive of my website using 7zip; there are a few directories that contain large files (several gigabytes) not worth backing up, as I already have backups of them. I could specify to backup only specific files or directories, but I'm planning on making a script to do this for me, and it'd be a bit annoying to keep updating the script to include new files, file types, and directories. I can't find for the life of me anything in the documentation about excluding directories; only files. What's the simplest way to go about doing this?

The command I used earlier (before I had large files to avoid) was simply

7z a backup.7z *

done in the working directory.

2 Answers 2

8

directory is a type of file. man 7z isn't easy to read but it mentions -x:

-x[r[-|0]]]{@listfile|!wildcard}
         

    Exclude filenames

Let's suppose we have a following directory tree:

$ tree
.
├── dir
│   └── file3
├── dir1
│   └── file4
├── file1
└── file2

2 directories, 4 files

and that we want to ignore dir and dir1:

$ 7z a -x'!dir' -x'!dir1' b.7z  *

After doing that:

$ 7z l b.7z
(...)
   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2018-04-03 22:25:24 ....A            0            0  file1
2018-04-03 22:25:24 ....A            0            0  file2
------------------- ----- ------------ ------------  ------------------------
2018-04-03 22:25:24                  0            0  2 files
1
  • How do you do the same thing if you don't know the name of the directories in advance?
    – wotter
    Apr 2, 2023 at 14:04
2

For me the syntax is slightly different.

NOW=`date +%Y-%m-%d-%H-%M-%S`
XX=`cat ~aaaaaazzzzzz/.gnupg2/passphrase-symmetric`
7z a                                           \
  -t7z -m0=lzma2 -mx=9 -mfb=64                 \
  -md=32m -ms=on -mhe=on -p${XX}               \
    '-xr!~/Documents/temp/'                    \
    '-xr!~/Documents/Sites/'                   \
    '-xr!**/*.zip'   '-xr!**/*.bz2'         '-xr!**/*.gz'   '-xr!**/*.7z'          \
    '-xr!**/*.pyc'   '-xr!**/__pycache__/**'                 \
    '-xr!**/*.gpkg'  '-xr!**/*.gramp' '-xr!**/*.ged'         \
    '-xr!**/*.log'   '-xr!*/venv/*' '-xr!*.sqlit*'  '-xr!*.bak'  '-xr!*.html~' '-xr!*.html~*'  \
    '-xr!*.vm'  '-xr!*.vmdk'  '-xr!*.vmem'  '-xr!*.vmsd'  '-xr!*.vmss'  '-xr!*.vmx'  '-xr!*.vmxf' \
    '-xr!*.mp4' '-xr!*.msf'                           \
    '-xr!*.htm' '-xr!*.html'                          \
   ${BACKUP_DIR}/data-encrypted/BackUp-${NOW}.7z      \
                    ~/Documents            \
                    ~/.ssh                 \
                    ~/.gnupg2              \
                    ~/.gnupg  

I run on Linux / Ubuntu

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 18, 2023 at 22:13

You must log in to answer this question.

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