7-zip update: skip operation if nothing has changed

6,180

Solution 1

Adding the "-stl" option sets the archives date/time to that of the last modified file. I made a test archive read-only, and got no error from 7zip when I "updated" when no files were changed. Caveat: When the "-mhe=on" option is used too, then the content of the archive is changed, but only when the update does not occur in the same minute as the previous update. In other words the "-mhe=on" always re-encrypts and re-stores headers and apparently uses the current time in minutes for that.

Solution 2

According to the manual, you should be able to specify a combination of state and action with the -u switch to precisely control in what cases you want the archive to be updated:

1

As an example demonstrates, 7z u c:\1\exist.7z -up0q3x2z0!c:\1\update.7z * -ms=off creates a new archive update.7z and writes to this archive all files from the current directory which differ from files in the exist.7z archive. If you omit the ! followed by the new archive name, then only the base or existing archive should get updated if the specified conditions are met.

Share:
6,180

Related videos on Youtube

Theo Tiger
Author by

Theo Tiger

Updated on September 18, 2022

Comments

  • Theo Tiger
    Theo Tiger over 1 year

    I am using 7-zip to backup folders on my disk into 7z archives on a network storage. Each time the backup script runs, it will update the existing archives in 7-zip update mode (compress new files from disk and copy unchanged files from the old archive). It works fine but involves two complete transfers of each archive over the network.

    Now, often the folder content has not changed at all since the last backup job, so it would be much more efficient to just skip the entire operation and leave the old archive as it is. How can I achieve this?

    • Karan
      Karan about 9 years
      Which OS are you running?
    • Theo Tiger
      Theo Tiger about 9 years
      It's Windows 7 x64.
  • Theo Tiger
    Theo Tiger about 9 years
    Thank you for your answer. That's all ok so far, but my problem is that even if no file was changed 7z still creates an update.7z, or, in my case, will update the exist.7z in-place. I would like to have 7z recognize that no file was changed and that there is thus no need to touch the exist.7z at all. Now, it produces massive network traffic (complete down- and re-upload of all the exist.7z's) and makes the backup job unnecessary slow.
  • Karan
    Karan about 9 years
    Does something like 7z u Exist.7z -u- -up0q0r2w2x0y2z0!Update.7z * not help?
  • Theo Tiger
    Theo Tiger about 9 years
    Unfortunately not: 7z still creates the Update.7z although no file was changed.
  • Karan
    Karan about 9 years
    But with -u- Exist.7z should be untouched. Moreover with the command I gave above Update.7z ought to have nothing inside but new/changed files. If it has files that are in Exist.7z then clearly the corresponding files on disk have either been updated or had their modified time changed.
  • Theo Tiger
    Theo Tiger about 9 years
    Yes you are right, but this would be incremental backup style. I prefer to have a single-file backup for this purpose. So, maybe I could do this in two steps: create an Update.7z with changed files only (as you described) and then merge Exist.7z and Update.7z. I am not sure how complicated that would be, I have to check the manual first.