Compare

Compare a list of files or directories with data stored in a backup directory.

$ hb compare [-c backupdir] [-v level] [-f] [-i attr1,attr2,...] -X
             [--sample p] pathname [pathname ...]

Displays files and directories that have been added, changed, or removed since the most recent backup. New files are marked with +, removed files are marked with -, and changed files are marked with !. For changed files, the changes are listed after the pathname.

-v control how much output is displayed, higher numbers for more:

  • -v0 = print version, backup directory, pathnames, changes, count of changes

  • -v1 = print names of skipped filesystems

  • -v2 = print detailed information about exactly what changed

  • -v3 = print names of excluded files

-r rev instead of comparing the most recent backup to the live filesystem, compare version rev.

-f generate a hash for each file and compare with the hash stored in the backup. Differences are noted with data in the changed attribute list. This option also forces a comparison of every inode attribute, even when it appears the file or directory has not been modified because ctime and inode have not changed.

-i ignore certain attributes (separated by commas, no spaces); attribute values are: ctime, gid, ino, mode, mtime, nlink, rdev, size, uid

-X cross mount points (descend into other filesystems)

--sample p specifies a percentage from 1 to 100 of files to sample for inclusion in the backup. This is a percentage of the files seen, not a percentage of the data in the files. This option only makes sense if the backup was created with the same sample percentage.

Examples

Example with no changes:

# hb compare -c /hb /System
HashBackup build 801 Copyright 2009-2012 HashBackup, LLC
Backup directory: /hb
This is backup version: 0
No files changed
No errors

Example with changes:

# hb compare -c /hb /Library
HashBackup build 801 Copyright 2009-2012 HashBackup, LLC
Backup directory: /hb
This is backup version: 0
! /Library/Keychains (mtime,ctime)
! /Library/Preferences (mtime,ctime)
! /Library/Preferences/com.apple.SoftwareUpdate.plist (ino,mtime,ctime)
! /Library/Printers (mtime,ctime)
! /Library/Printers/InstalledPrinters.plist (ino,size,mtime,ctime)
! /Library/Updates (mtime,ctime)
! /Library/Updates/ProductMetadata.plist (ino,mtime,ctime)
7 files changed
No errors`

The same example, ignoring some attributes:

# hb compare -c /hb /Library -i mtime,ctime
HashBackup build 801 Copyright 2009-2012 HashBackup, LLC
Backup directory: /hb
This is backup version: 0
! /Library/Preferences/com.apple.SoftwareUpdate.plist (ino)
! /Library/Printers/InstalledPrinters.plist (ino,size)
! /Library/Updates/ProductMetadata.plist (ino)
3 files changed
No errors

Example showing new, changed, and removed files:

sh-3.2# hb compare -c /hb /private/etc
HashBackup build 801 Copyright 2009-2012 HashBackup, LLC
Backup directory: /hb
This is backup version: 0
! /private/etc (mtime,ctime)
! /private/etc/cups/certs (mtime,ctime)
! /private/etc/cups/certs/0 (ino,mtime,ctime)
! /private/etc/dnscache/log/main (mtime,ctime)
- /private/etc/dnscache/log/main/@4000000050c2a0560119f98c.s
- /private/etc/dnscache/log/main/@4000000050c2a0fb0e988ca4.s
+ /private/etc/dnscache/log/main/@4000000050c36a0a169fd4fc.s
+ /private/etc/dnscache/log/main/@4000000050c36a0e34b4ddd4.s
+ /private/etc/dnscache/log/main/@4000000050c36aa1297cc7ec.s
! /private/etc/dnscache/log/main/current (ino,size,mtime,ctime)
! /private/etc/hosts (ino,size,mtime,ctime)
- /private/etc/hosts.~24~
+ /private/etc/hosts.~26~
26 files changed
No errors

Example comparing older backup versions:

In this test:

  • a small directory ls is saved

  • the directory is backed up

  • file abc is added

  • the directory is backed up again (version 1)

  • file abc has data appended to it

  • the version 1 backup is compared to the ls directory

  • the version 1 backup of just file abc is compared

$ hb backup -c hb ls
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Backup start: 2022-01-10 13:06:31
This is backup version: 0
Dedup not enabled; use -Dmemsize to enable
/
/Users
/Users/jim
/Users/jim/hbrel
/Users/jim/hbrel/hb
/Users/jim/hbrel/hb/inex.conf
/Users/jim/hbrel/ls
/Users/jim/hbrel/ls/find.new
/Users/jim/hbrel/ls/find.py
/Users/jim/hbrel/ls/ls.py
/Users/jim/hbrel/ls/lsx1.py
/Users/jim/hbrel/ls/msls.py
/Users/jim/hbrel/ls/mslsx.py
/Users/jim/hbrel/ls/pathscmd.py

Time: 0.1s
CPU:  0.0s, 81%
Mem:  59 MB
Checked: 14 paths, 89393 bytes, 89 KB
Saved: 14 paths, 89393 bytes, 89 KB
Excluded: 0
Dupbytes: 0
Compression: 89%, 9.1:1
Efficiency: 0.00 MB reduced/cpusec
Space: +9.7 KB, 157 KB total
No errors
$ hb compare -c hb ls
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Comparing most recent backup to filesystem
No files changed
No errors
$ echo abc >ls/abc
$ hb backup -c hb ls
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Backup start: 2022-01-10 13:06:58
This is backup version: 1
Dedup not enabled; use -Dmemsize to enable
/
/Users
/Users/jim
/Users/jim/hbrel
/Users/jim/hbrel/hb
/Users/jim/hbrel/ls
/Users/jim/hbrel/ls/abc

Time: 0.1s
CPU:  0.1s, 87%
Mem:  58 MB
Checked: 15 paths, 89397 bytes, 89 KB
Saved: 7 paths, 4 bytes, 4 bytes
Excluded: 0
Dupbytes: 0
Space: +16 bytes, 157 KB total
No errors
$ hb compare -c hb ls
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Comparing most recent backup to filesystem
No files changed
No errors
$ hb compare -c hb ls -r0
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Comparing version 0 backup to filesystem
! /Users/jim/hbrel/ls (mtime,ctime)
+ /Users/jim/hbrel/ls/abc
2 files changed
No errors
$ hb compare -c hb ls -r0 -v2
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Comparing version 0 backup to filesystem
! /Users/jim/hbrel/ls (mtime,ctime)
  * Mtime: 2022-01-10 13:06:24 (1641837984) 2022-01-10 13:06:53 (1641838013)
  * Ctime: 2022-01-10 13:06:24 (1641837984) 2022-01-10 13:06:53 (1641838013)
+ /Users/jim/hbrel/ls/abc

Time: 0.0s
Files: 13
New: 1
Changed: 1
Deleted: 0
Excluded: 0
No errors
$ echo def >>ls/abc
$ hb compare -c hb ls -r0
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Comparing version 0 backup to filesystem
! /Users/jim/hbrel/ls (mtime,ctime)
+ /Users/jim/hbrel/ls/abc
2 files changed
No errors
$ hb compare -c hb ls -r0 -v2
HashBackup #2659 Copyright 2009-2022 HashBackup, LLC
Backup directory: /Users/jim/hbrel/hb
Comparing version 0 backup to filesystem
! /Users/jim/hbrel/ls (mtime,ctime)
  * Mtime: 2022-01-10 13:06:24 (1641837984) 2022-01-10 13:06:53 (1641838013)
  * Ctime: 2022-01-10 13:06:24 (1641837984) 2022-01-10 13:06:53 (1641838013)
+ /Users/jim/hbrel/ls/abc

Time: 0.0s
Files: 13
New: 1
Changed: 1
Deleted: 0
Excluded: 0
No errors

Notes

  • with -v0, a file or directory with the "nodump" bit set will display as added

  • with -v0, a new directory displays as added but its contents are not displayed

  • deleted directories display as removed, with …​ added, but the contents are not displayed

  • extended attributes and ACLs should be compared when -f is used, but aren’t

  • symbolic link values should be compared when -f is used, but aren’t

  • compare exits with 1 if errors occur

  • compare should also exit with a non-zero error if any changes are detected, but exits with zero