Update archive does not remove files?

Help
2010-09-20
2014-08-01
  • Omega Weapon
    Omega Weapon
    2010-09-20

    I would like to use '7z' to create an archive of a few folders, and then on subsequent updates it should update, add and importantly delete files in the archive as appropriate.

    So far it appears that 7z does not delete files in an archive - the best I can see on this is the following in the '-u' documentation:

    Create Anti-item (item that will delete file or directory during extracting). This feature is supported only in 7z format.

    This does not sound like removing a file from an archive, but modifying the filesystem that you are extracting to.

    Basically, for state 'File exists in archive, but doesn't exist on disk.', I need a deletion action - I am currently recreating some WinRAR backup scripts with 7z.

    Am I missing something, or does 7z not allow deletion of archive contents on an update?

    Thanks for any help.

     
  • Igor Pavlov
    Igor Pavlov
    2010-09-21

    if you need Synchronize, use the following command:
    7z u a.7z -uq0 Files

    -uq0 tells to use 0 (Ignore file (don't create item in new archive for this file))
    instead of 1 (Copy file (copy from old archive to new)) of update command
    for "q" (File exists in archive, but doesn't exist on disk).

     
  • Omega Weapon
    Omega Weapon
    2010-09-21

    Hi ipavlov,

    Thanks for responding so fast :)

    OK, it looks like I have an understanding problem here. When I say 'update an archive', I mean that the archive that is being  operated on is updated in place - there is no 'new archive', 7z needs to compare the contents of the current filesystem with the archived folder and update, add or delete files in the archive as appropriate.

    Are you saying that 7z can only create a new archive based on the old one? (Sounds no different from just creating from scratch for my purposes).

    Thanks.

     
  • Igor Pavlov
    Igor Pavlov
    2010-09-21

    - Are you saying that 7z can only create a new archive based on the old one? (Sounds
    no different from just creating from scratch for my purposes).

    Yes, it's safe way.
    If everything  is OK, it renames temp.7z to old_name.7z

    If you update non-solid archive, you don't compress all files. So it's faster than creating new archive.

     
  • Omega Weapon
    Omega Weapon
    2010-09-21

    Thanks for clearing this up - since I think solid is on by default, that'll be something I need to disable.

    I'll have a go with this after work today, thanks for your help.

     
  • Omega Weapon
    Omega Weapon
    2010-09-21

    Hell, couldnt help myself so I tested now - yes, it works perfectly. Because its a small test it looks from my perspective like the archive was updated in place, which is great.

    It would be good if you could update the documentation slightly to spell out that you need the extra '-uq0' parameter to realise a true update on an archive (my definition of update includes deletion ;))

    Thanks for your help

     
  • Superole
    Superole
    2013-04-25

    I have to say thank you for clearing this up as well :)
    I don't know why I didn't test this before, after all the saying When in doubt there is no doubt - Test it applies here.
    Instead I first went for the q3 alternative.

    and FYI @omega_weapon: if you use exclude switch (-x), I find it's a good idea to add p0 also (-up0q0). Then it will remove a file from archive if it is added to the list of excludes(even if it is still on disk).

     
  • MaX
    MaX
    2014-07-31

    is there a way to have the -uq0 effect also when unpacking files from an archive?
    I try to clarify: if my archive does not have the file myFile.txt and in my target folder I have the file myFile.txt is there a switch that will remove the myFile.txt from the target folder?

     
    • Igor Pavlov
      Igor Pavlov
      2014-08-01

      Remove all files from target folder and then unpack archive.