How to re-scan Owncloud files

I recently had an issue where my MariaDB data share got corrupted and I had to restore from an earlier snapshot (see
Owncloud-official blank screen, “Read-only file system” error – mariadb issue

The problem was, the latest snapshot was about a month older than the contents of my Owncloud share. Owncloud had files in there that the database didn’t know were there.

So I had to figure out how to rescan all my Owncloud data. Here’s what I figured out:

docker exec -it owncloud-official bash
(substitute the name of your Owncloud container for owncloud-official)
su -s /bin/bash www-data ./occ files:scan --all

Further advice: it’s probably best if you do that before any of your clients connect to your OC instance. And it’s probably a good idea to back up any content you’ve added or changed since the last sync ran.