This toolkit helps Nextcloud discover files copied directly on the NAS by running occ files:scan via a web UI (script_server), without needing SSH for day-to-day use.
✅ Privacy note: This repository is intentionally anonymized. Replace placeholders (container name, host paths, usernames) using your local
scripts/config.sh(not committed).
If you copy files directly into the Nextcloud data directory on the host (NAS) rather than uploading via the Nextcloud web UI / WebDAV / Desktop client, Nextcloud won't automatically update its file cache. You must run:
occ files:scan --all(all users / all files), orocc files:scan --path="<user>/files/<folder>"(scoped scan)
This toolkit provides web buttons to run these scans, plus logging and log cleanup.
nextcloud-rescan-toolkit/
README.md
.gitignore
scripts/
config.sample.sh
nextcloud_scan.sh
nextcloud_show_last_log.sh
nextcloud_list_scan_logs.sh
nextcloud_cleanup_scan_logs_keep_last.sh
Not committed:
scripts/config.sh(your real environment values)- scan logs (ignored by
.gitignore)
- Nextcloud running in Docker on an Asustor NAS (ADM)
- You have a way to run scripts on the NAS:
- script_server (recommended) for a web UI, or
- SSH for initial setup only
Copy the sample:
- From:
scripts/config.sample.sh - To:
scripts/config.sh
Fill in your real values:
NC_CONTAINER— Docker container name running NextcloudNC_OCC— path tooccinside the container (often/var/www/html/occ)NC_RUN_UID— UID to runoccas (commonly33forwww-data)NC_LOG_DIR— host directory where logs should be written
Example (placeholder-only):
NC_CONTAINER="nextcloud"
NC_OCC="/var/www/html/occ"
NC_RUN_UID="33"
NC_LOG_DIR="/path/to/scan_logs"Main entrypoint.
Supported modes:
- Scan everything:
mode=all
- Scan user or subfolder:
mode=path user=<USER> folder=<FOLDER>- If
folderis empty, scans<USER>/files
- Manual path override:
mode=path scan_path=<USER>/files/<FOLDER>
It writes a log file for each run:
nextcloud_scan_all_YYYYMMDD_HHMMSS.lognextcloud_scan_path_YYYYMMDD_HHMMSS.log
Shows the tail of the most recent scan log.
- Accepts an optional numeric argument (lines), default 200.
Lists the latest scan logs (newest first). Default shows 30.
Deletes old logs and keeps only the newest N logs (default 20).
Install script_server from ADM App Central.
Open the admin page:
http://<NAS-IP>:<SCRIPT_SERVER_PORT>/admin.html
Create a group named Nextcloud (optional).
- Script:
scripts/nextcloud_scan.sh - Parameters:
mode(list):all,pathuser(list): your Nextcloud usernames (must match folder names under<DATA_DIR>/<user>/)folder(text): e.g.PhotosorDocuments/2025(optional)scan_path(text): advanced override, e.g.<USER>/files/<FOLDER>
Usage:
- All users:
mode=all - Single user root:
mode=path user=USER folder=(empty)→ scansUSER/files - Subfolder:
mode=path user=USER folder=Photos→ scansUSER/files/Photos
- Script:
scripts/nextcloud_scan.sh - Default
mode=all
- Script:
scripts/nextcloud_show_last_log.sh - Parameter:
lines(number, default 200)
- Script:
scripts/nextcloud_list_scan_logs.sh - Parameter:
count(number, default 30)
- Script:
scripts/nextcloud_cleanup_scan_logs_keep_last.sh - Parameter:
keep(number, default 20)
Scan logs are written to:
NC_LOG_DIR(fromscripts/config.sh)
Recommended naming:
nextcloud_scan_all_YYYYMMDD_HHMMSS.lognextcloud_scan_path_YYYYMMDD_HHMMSS.log
If occ says it must be executed by the owner of config/config.php, align ownership and permissions to the web user (commonly www-data, UID 33), in a way that matches your environment.
Nextcloud expects a marker file .ncdata in the root of the data directory.
If files were copied with incorrect ownership/permissions, Nextcloud may not read them. Fix ownership to match your container's expected user.
- Don’t expose script_server publicly without authentication and network restrictions.
- Treat these scripts as privileged operations: they call
docker exec. - Never commit your
scripts/config.sh.
-
Copy the
scripts/folder from this repo to your NAS (any location you prefer). -
Make scripts executable on the NAS:
chmod +x /path/to/scripts/*.sh
-
On the NAS, copy the sample config:
cp /path/to/scripts/config.sample.sh /path/to/scripts/config.sh
-
Edit
config.shand set your real values:NC_CONTAINER— your Nextcloud container nameNC_OCC— path tooccinside the container (often/var/www/html/occ)NC_RUN_UID— UID foroccexecution (commonly33)NC_LOG_DIR— host directory for logs (recommended: a persistent folder)
Never commit
scripts/config.sh.
-
Scan all users:
/path/to/scripts/nextcloud_scan.sh mode all
-
Scan a specific user:
/path/to/scripts/nextcloud_scan.sh mode path user USER_A
-
Scan a user subfolder:
/path/to/scripts/nextcloud_scan.sh mode path user USER_A folder Photos
-
Install
script_serverin ADM. -
Open admin panel:
http://<NAS-IP>:<SCRIPT_SERVER_PORT>/admin.html
-
Add buttons pointing to the scripts in
scripts/:nextcloud_scan.sh(mode dropdown + user dropdown + folder text)nextcloud_show_last_log.shnextcloud_list_scan_logs.shnextcloud_cleanup_scan_logs_keep_last.sh
Logs are written to NC_LOG_DIR.