---
title: "Rescan a File Share Incrementally with Phinder's Scan Log"
description: "Keep a file share's PII scan current without rescanning every file: Phinder's MongoDB scan log skips unchanged files and keeps a history of reports."
url: "https://philterd.ai/guides/rescan-a-file-share-incrementally-with-phinder/"
---

[Knowledge base](https://philterd.ai/guides/) [How-to](https://philterd.ai/guides/?kind=how-to)

# Rescan a File Share Incrementally with Phinder's Scan Log

Keep a file share's PII scan current without rescanning every file: Phinder's MongoDB scan log skips unchanged files and keeps a history of reports.

For [Phinder](https://philterd.ai/support/phinder/)

A file share that people keep using needs more than one PII scan. New files arrive, old ones get edited, and a scan from last quarter no longer describes what is there. Rescanning everything each time is slow on a large share, and most of the files have not changed.

[Phinder](https://philterd.ai/phinder/)’s scan log records a hash of every file it scans in MongoDB. With `--skip-unchanged`, the next run skips any file whose content has the same hash and scans only what is new or changed. Each run’s results also go into a report history in the same database.

This guide sets up the scan log, rescans a small invented share after changing it, and shows the catch: a run’s report covers only the files it scanned, so the full picture comes from the history.

Detection is probabilistic, so validate what a scan reports against your own data.

![The first run scans all five files of a share and records an xxHash64 hash of each in Phinder's scan log in MongoDB. After one file is edited and one is added, the second run compares hashes, skips the four unchanged files, and scans the two that are new or changed. Each run's report covers only the files it scanned, and every report is kept in the reports collection, so the history gives the latest result for each file.](https://philterd.ai/images/guides/guide-phinder-incremental-rescan.svg)

## Before you start

You need Phinder built from source, as described in [Find the PII in a folder with Phinder](https://philterd.ai/guides/find-pii-in-a-folder-with-phinder/), and a MongoDB that Phinder can reach. For a local test:

```bash
docker run -d --name phinder-mongo -p 127.0.0.1:27017:27017 mongo:8.2.12
```

Phinder takes the connection string from the `--mongodb` option. It does not read a `PHINDER_MONGODB_URI` environment variable, and without `--mongodb` a run with `--log` or `--skip-unchanged` stops at once:

```text
MongoDB URI is required when using --log, --skip-unchanged, or --clean. Use --mongodb to specify the URI.
```

It uses a database named `phinder`, with three collections: `file_hashes`, `scanned_paths`, and `reports`.

## 1\. Run the first scan

```bash
mkdir -p ~/scans/claims-share/run-1 && cd ~/scans/claims-share/run-1
java -jar phinder.jar -i /mnt/claims-share -R \
  --mongodb "mongodb://localhost:27017" --skip-unchanged > console.txt 2> errors.txt
jq '{filesScanned, skippedFiles, filesFailed}' report.json
```

```json
{
  "filesScanned": 5,
  "skippedFiles": 0,
  "filesFailed": 0
}
```

With an empty scan log, nothing is skipped. Every file scanned successfully now has a hash in `file_hashes`, keyed by its absolute path:

```bash
docker exec phinder-mongo mongosh --quiet phinder \
  --eval 'db.file_hashes.find({}, {_id: 0}).sort({file_path: 1}).limit(2).toArray()'
```

```text
[
  {
    file_path: '/mnt/claims-share/claims/claim-10482.txt',
    hash: '60f084c285d7181a'
  },
  {
    file_path: '/mnt/claims-share/claims/claim-10483.txt',
    hash: '020efae50fdfa02b'
  }
]
```

`--skip-unchanged` turns on the scan log by itself. `--log` alone records hashes and reports but scans every file.

## 2\. Rescan after a change

Before the next run, someone appends a note with a phone number to `claim-10483.txt` and adds a new claim, `claim-10484.txt`. Run the same command from a new directory:

```bash
mkdir -p ~/scans/claims-share/run-2 && cd ~/scans/claims-share/run-2
java -jar phinder.jar -i /mnt/claims-share -R \
  --mongodb "mongodb://localhost:27017" --skip-unchanged > console.txt 2> errors.txt
grep -E "Skipping|PII found in" console.txt
jq '{filesScanned, skippedFiles, aggregateRiskLevel}' report.json
```

```text
PII found in claim-10483.txt:
Skipping unchanged file: vendor-contacts.docx
Skipping unchanged file: claim-10482.txt
PII found in claim-10484.txt:
Skipping unchanged file: onboarding-checklist.md
Skipping unchanged file: handbook-excerpt.txt
```

```json
{
  "filesScanned": 2,
  "skippedFiles": 4,
  "aggregateRiskLevel": "MEDIUM"
}
```

Phinder still reads every file to compute its xxHash64 hash, so a skip saves text extraction and detection, not the read. The saving is largest for PDFs, Office files, and images, where extraction and OCR take most of the time.

## 3\. Do not read one run’s report as the whole share

`report.html` and `report.json` cover only the files that run scanned. A rerun with nothing changed produces a report that looks clean. This one ran between the first and second scans, when the share had five files:

```json
{
  "filesScanned": 0,
  "skippedFiles": 5,
  "aggregateCounts": {},
  "aggregateRiskLevel": "NONE"
}
```

The skipped files still hold the PII they held before. Phinder also writes both reports to the current directory and overwrites any already there, so give each run its own directory, as above, to keep the earlier reports.

## 4\. Get the latest result for every file

Every run with `--mongodb` adds a report to the `reports` collection, with a timestamp, `skipped_files`, `failed_files`, aggregate scores and counts, and a `per_file_results` entry for each file it scanned. The entries hold counts, scores, and confidence statistics, not the detected values.

To see the current state of the share, take the most recent result for each file across all runs:

```bash
docker exec phinder-mongo mongosh --quiet phinder --eval '
db.reports.aggregate([
  { $sort: { timestamp: 1 } },
  { $unwind: "$per_file_results" },
  { $group: {
      _id: "$per_file_results.file_path",
      risk_level: { $last: "$per_file_results.risk_level" },
      counts: { $last: "$per_file_results.counts" } } },
  { $sort: { _id: 1 } }
])'
```

```text
[
  {
    _id: '/mnt/claims-share/claims/claim-10482.txt',
    risk_level: 'MEDIUM',
    counts: {
      date: 1,
      'phone-number': 1,
      'email-address': 1,
      'zip-code': 2,
      ssn: 1
    }
  },
  {
    _id: '/mnt/claims-share/claims/claim-10483.txt',
    risk_level: 'MEDIUM',
    counts: {
      'phone-number': 1,
      'email-address': 1,
      vin: 1,
      'zip-code': 2,
      'first-name': 2
    }
  },
  {
    _id: '/mnt/claims-share/claims/claim-10484.txt',
    risk_level: 'MEDIUM',
    counts: { 'email-address': 1, 'zip-code': 2, ssn: 1 }
  },
  ...
]
```

`claim-10482.txt` comes from the first run and the other two from the second, so the result covers all six files. Two limits:

- A deleted file stays in the result, because nothing records that it is gone. Compare the paths with the share’s current file list.
- The paths are absolute. Mount the share at the same path on every run, or every file looks new and is rescanned.

## 5\. Know when to rescan everything

A skip depends only on the file’s hash. Phinder does not check whether the policy, the weights, or Phinder itself changed since the file was scanned, so after any of these, rescan everything:

- you pass a different policy with `-p`
- you upgrade Phinder, whose detection may change between versions
- you want risk scores computed with new `--severities`

`--clean` empties the scan log before the run. It needs `--input` like any other run, so combine it with the rescan:

```bash
java -jar phinder.jar -i /mnt/claims-share -R \
  --mongodb "mongodb://localhost:27017" --skip-unchanged --clean > console.txt 2> errors.txt
grep "Scan log cleaned" console.txt
```

```text
Scan log cleaned.
```

`--clean` empties all three collections, including `reports`, so the report history goes too. Export it first if you want to keep it:

```bash
docker exec phinder-mongo mongoexport --quiet --db phinder --collection reports > phinder-reports.json
```

## Protect the scan log

The scan log holds no detected values, but it does hold the full path of every file scanned and, in `reports`, which kinds of PII each file contains and how many. File paths often name people, customers, or cases. Restrict access to the MongoDB database the way you would restrict the share itself, and require authentication on it.
