Why restore the database when occ files:scan --all seems to be enough?

Hey guys, I’ve got quite a silly question, so bear with me please :slight_smile:

so my question is about how Nextcloud handles files and database consistency

Here’s my setup:

  • I have a running instance that we gonna call NC1

  • Last week, I made a database backup of NC1

  • I then deployed a new instance, NC2, which is basically NC1 from last week

  • copied all the files from NC1’s data/ directory to NC2

What I did today, is I copied all file from NC1 to NC2, which means NC2 is up to date on files, but the db is still from last week,

So now I’m wondering: instead of restoring NC1’s newest database backup on NC2, why can’t I just run :

occ files:scan --all

on NC2 and let it rebuild everything automatically?

From what I understand, files:scan updates the file cache in the database based on what’s physically present in the data directory, so if I already have all the files, what does restoring the new database add that the scan wouldn’t handle?

So basicly my question is :

When should I restore the database, and when is it enough to just run “occ files:scan --all” after copying the files?

Everything else. So if you have shares for example, tags, link of files with other apps, other app data, … For new setups less of a problem, but for current ones, what will the connected clients do, especially if they have unsynced changes, they might be overwritten or deleted.

If you start a new setup, you put a lot of files (or connect a storage), the files:scan is the right tool to use. After that, it should not be required to use it, since all the transfers should happen through Nextcloud. If you need parallel different access, you have the external storage feature that allows changes by other processes.

Hello Samir,

occ files:scan --all only rebuilds the file cache table based on what’s physically in the data folder. It doesn’t restore file shares, versions, comments, activity history, tags, or any app-specific data.

So, if you only care about having the files show up again (for example, after manually copying data), running files:scan is fine.

But if you want to fully restore your instance, including users’ shares, versions, and metadata, you need to restore the database as well. The database holds all that extra information, not just the file list.

If NC2 should be an exact clone of NC1, restore both the data folder and the latest database backup.

Marvin – Accuweb.Cloud Support Engineer