0

NOTE TO MODERATOR:

While it is true that there is a question out there that has several conflicting answers to this very question, as I have pointed out in a comment to that question, none of those answers works in this situation. In fact, I even originally mentioned that other post in this post, and explained that it doesn't work for me. I understand and agree with the idea that, in a perfect world, I'd find my answer there and move along. But this world is not perfect, and none of those answers helps this situation, and I cannot explain why. So there is nothing really that I can do (short of giving a false answer in the other post - which is also opposed to SO rules and I wouldn't anyway) to make anyone notice it again or continue the discussion. I would appreciate if you DM me or otherwise contact me to explain how the existence of a question with answers that do not work should interfere with solving a user's problem. Somehow I don't get it.

END OF NOTE

In our users' home directories on some servers, are two rather large subdirectories that we feel do not need backed up on a daily basis. One is the ridiculously-large .config/chromiu/*, and the other is .vscode

The zip manpage description for excluding files reads:

   -x files
   --exclude files
          Explicitly exclude the specified files, as in:

                 zip -r foo foo -x \*.o

          which  will include the contents of foo in foo.zip while excluding all the files that end in .o.  The backslash avoids the shell filename substitution, so that the name match‐
          ing is performed by zip at all directory levels.

          Also possible:

                 zip -r foo foo [email protected]

          which will include the contents of foo in foo.zip while excluding all the files that match the patterns in the file exclude.lst.

          The long option forms of the above are

                 zip -r foo foo --exclude \*.o

          and

                 zip -r foo foo --exclude @exclude.lst

          Multiple patterns can be specified, as in:

                 zip -r foo foo -x \*.o \*.c

          If there is no space between -x and the pattern, just one value is assumed (no list):

                 zip -r foo foo -x\*.o

          See -i for more on include and exclude.

Relying on this, the script that dynamically performs the backup executes the following command: (4 example attempts)

zip --symlinks --recurse-paths --quiet /usr/local/backups/home_realuser-daily-2024-06-19.zip '/home/realuser/' -x '/home/realuser/.config/chromium/*' '/home/realuser/.config/chromium/*'
zip --symlinks --recurse-paths --quiet /usr/local/backups/home_realuser-daily-2024-06-19.zip '/home/realuser/' -x '/home/realuser/.config/chromium/\*' '/home/realuser/.config/chromium/\*'
zip --symlinks --recurse-paths --quiet /usr/local/backups/home_realuser-daily-2024-06-19.zip '/home/realuser/' -x /home/realuser/.config/chromium/\* /home/realuser/.config/chromium/\*
zip --symlinks --recurse-paths --quiet /usr/local/backups/home_realuser-daily-2024-06-19.zip '/home/realuser/' -x home/realuser/.config/chromium/\* home/realuser/.config/chromium/\*
zip --symlinks --recurse-paths --quiet /usr/local/backups/home_realuser-daily-2024-06-19.zip '/home/realuser/' -x '/home/realuser/.config/chromium/**\*' '.home/realuser/.cache/chromium/**\*' 2>&1
zip --symlinks --recurse-paths --quiet /usr/local/backups/home_realuser-daily-2024-06-19.zip /home/realuser/ -x home/realuser/.config/chromium/**\* home/realuser/.config/chromium/**\*

Even so, with any of these commands, when we list the items in the backup, we find there are thousands of entries in the backup for this folder:

> unzip -l home_realuser-yrly-2024.zip |grep config.*chromium|more
        0  2022-01-30 20:49   home/realuser/.config/chromium/
        0  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/
        0  2022-01-02 22:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211228.417190741/
       66  2022-01-02 22:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211228.417190741/manifest.fingerprint
        0  2022-01-02 22:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211228.417190741/_metadata/
     1820  2022-01-02 22:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211228.417190741/_metadata/verified_contents.json
      196  2022-01-02 22:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211228.417190741/manifest.json
  1392766  2022-01-02 22:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211228.417190741/tl_en-us_2021-12-28_417190741_100000_index.bin
        0  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20220112.419803486/
       66  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20220112.419803486/manifest.fingerprint
  1392146  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20220112.419803486/tl_en-us_2022-01-12_419803486_100000_index.bin
        0  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20220112.419803486/_metadata/
     1820  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20220112.419803486/_metadata/verified_contents.json
      196  2022-01-18 03:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20220112.419803486/manifest.json
        0  2021-12-05 19:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211128.413282013/
       66  2021-12-05 19:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211128.413282013/manifest.fingerprint
  1391993  2021-12-05 19:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211128.413282013/tl_en-us_2021-11-28_413282013_100000_index.bin
        0  2021-12-05 19:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211128.413282013/_metadata/
     1820  2021-12-05 19:48   home/realuser/.config/chromium/OnDeviceHeadSuggestModel/20211128.413282013/_metadata/verified_contents.json

and so on. What must we do in order to exclude folders like this from the backup?

(The backup command is executed with / (root) as present working directory, so /home is the same as home.)

The same thing happens with .vscode (or any other folders we try to exclude) - it just happens that this user lacks .vscode on this system.

We've found answers on SO that indicate we're doing it correctly in at least most of these iterations, though some differ regarding what happens when the directories are quotated. Examples are ubuntu: How to zip a directory in ubuntu by excluding some subdirectories from command line and Unix zip directory but excluded specific subdirectories (and everything within them)

The output of zip -v is:

Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
Currently maintained by E. Gordon.  Please send bug reports to
the authors using the web page at www.info-zip.org; see README for details.

Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,
as of above date; see http://www.info-zip.org/ for other sites.

Compiled with gcc 4.9.3 for Unix (Linux ELF).

Zip special compilation options:
        USE_EF_UT_TIME       (store Universal Time)
        BZIP2_SUPPORT        (bzip2 library version 1.0.6, 6-Sept-2010)
            bzip2 code and library copyright (c) Julian R Seward
            (See the bzip2 license for terms of use)
        SYMLINK_SUPPORT      (symbolic links supported)
        LARGE_FILE_SUPPORT   (can read and write large files on file system)
        ZIP64_SUPPORT        (use Zip64 to store large files in archives)
        UNICODE_SUPPORT      (store and read UTF-8 Unicode paths)
        STORE_UNIX_UIDs_GIDs (store UID/GID sizes/values using new extra field)
        UIDGID_NOT_16BIT     (old Unix 16-bit UID/GID extra field not used)
        [encryption, version 2.91 of 05 Jan 2007] (modified for Zip 3)

Encryption notice:
        The encryption code of this program is not copyrighted and is
        put in the public domain.  It was originally written in Europe
        and, to the best of our knowledge, can be freely distributed
        in both source and object forms from any country, including
        the USA under License Exception TSU of the U.S. Export
        Administration Regulations (section 740.13(e)) of 6 June 2002.

Zip environment options:
             ZIP:  [none]
          ZIPOPT:  [none]
0

0

Browse other questions tagged .