If you were to do an incremental backup, you would need to provide 7-zip with the list of the files modified (with -i@fileList
), and you would need to elaborate such list somehow. At the archive.org mirror of removed question Offline incremantal backup via thumbdrive you can find a Unix command line using md5 signatures to create the fileList.
The 7-zip update operation allows to create a secondary archive with the differences (including deleted files) occurring since the base/primary archive. That is properly named a differential backup (as stated in the question itself).
I've found an excellent article on this topic at WPCTips "Differential Backups with 7-zip"(archived). They recommend either using a GUI program (Toucan), or use this recipe for the command line:
7z u {base archive.7z} -u- -"up0q3r2x2y2z0w2!{differential.7z}" {folder to archive}
This is a bit different from the 7zr u -up0q3r2x2y2z1w2 {archive}.7z {path}
proposed by ArtemGr:
-u-
tells the main archive should not be modified
"-up0q3r2x2y2z0w2!{differential.7z}"
specifies the target differential archive, and what action to do for each file for each condition/state: add files which are new or modified in the filesystem, remove files which are only in the 7zip archive, ignore the rest.
Notice that the "!" character will be intercepted by bash
unless it is quoted.
Just in case you are curious about the specifics of that cryptic p0q3r2x2y2z0w2
<state> | State condition
p | File exists in archive, but is not matched with wildcard. Exists, but is not matched
q | File exists in archive, but doesn't exist on disk.
r | File doesn't exist in archive, but exists on disk.
x | File in archive is newer than the file on disk.
y | File in archive is older than the file on disk.
z | File in archive is same as the file on disk
w | Can not be detected what file is newer (times are the same, sizes are different)
<action> | Description
0 | Ignore file (don't create item in new archive for this file)
1 | Copy file (copy from old archive to new)
2 | Compress (compress file from disk to new archive)
3 | Create Anti-item (item that will delete file or directory during extracting). This feature is supported only in 7z format.
Hello, what do those many options mean? – Zhianc – 2015-04-27T07:34:40.790
It's a map from a file state to an action. There are seven possible states. – ArtemGr – 2015-04-27T12:06:10.033
3It's not an incremental backup. This command makes a differential backup and creates new archive with changes since last full backup. Incremental backup tracks changes since previous incremental backup (diff of diff). – stil – 2016-02-07T21:11:07.403
I think this is plain wrong, in that it just updates archive.7z to be almost the same as just creating a new archive, but a bit quicker as it will reuse. Javier's answer below seems to be a differential. – Tuntable – 2018-12-12T07:21:23.327
When the archive is large and the increments are small the "bit quicker" is quite substantial. Not repacking the entire archive is one of the points of the incremental backups. Also, this is not a differential backup: we're updating the main archive and not storing the difference in a separate archive. If you like the other solutions more, feel free to upvote them, there's more than one way to skin a cat. – ArtemGr – 2018-12-12T23:06:43.850