Problems with timestamp and oc_filecache

Nextcloud version (eg, 20.0.5): 25.0.1
Operating system and version (eg, Ubuntu 20.04): CentOS Linux release 7.9.2009
Apache or nginx version (eg, Apache 2.4.25): 2.4.6
PHP version (eg, 7.4): 7.4.32

The issue you are facing:
Some Files have incorrect Timestamps. Most of them have 01.01.1970. But also I found 25.05.1917. This timestamp is also on the file on the filesystem (stat was used).
I also have found the nearly the same issues from other people. But there are some differences to my problem.
It only affected around 400 Files of more than 3 million files.
Not all files in a folder were affected.
Also files were affected, which weren’t synced with a client. We have the user “trash”, which owns all old files which weren’t sorted out when we moved to Nextcloud. These files aren’t shared with anybody and only I have access to this account. Other issues are referring to a client error - I can exclude that this is a client error.

I’ve changed the mtime of all affected files to the ctime of the file on the machine. Found with find /nextcloud_data/ -type f -newermt "1800-01-01" ! -newermt "1971-01-01".
Then I ran occ files:scan --path for all folders which had files with incorrect timestamps.

In the table oc_filecache are still some files with mtime and storage_mtime set to a negative value, for example -1660064354, despite running the occ files:scan --path for the corresponding path, where the file now has the correct mtime.

I digged a little bit deeper and checked for a specific file.
SELECT * FROM oc_filecache WHERE path LIKE '%/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README';

+----------+---------+--------------------------------------------------------------------+----------------------------------+----------+--------+----------+----------+------+------------+---------------+-----------+------------------+----------------------------------+-------------+----------+
| fileid   | storage | path                                                               | path_hash                        | parent   | name   | mimetype | mimepart | size | mtime      | storage_mtime | encrypted | unencrypted_size | etag                             | permissions | checksum |
+----------+---------+--------------------------------------------------------------------+----------------------------------+----------+--------+----------+----------+------+------------+---------------+-----------+------------------+----------------------------------+-------------+----------+
|  3726043 |      88 | files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README            | d97c2482f7a269d154c9f463b026e901 |  3725896 | README |       12 |        3 | 1190 | 1497335767 |    1497335767 |         0 |                0 | f83b9a6c94a6dedd166bced1c69662c6 |          27 |          |
| 11435339 |      25 | TRASH/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README.     | fc319e5ce87a1beed22f650e9b65c13a | 11435192 | README |       12 |        3 | 1190 |-1660064354 |   -1660064354 |         0 |                0 | 70086ed42fe2bb4eb366aefb14d021f1 |          27 |          |
+----------+---------+--------------------------------------------------------------------+----------------------------------+----------+--------+----------+----------+------+------------+---------------+-----------+------------------+----------------------------------+-------------+----------+

Same file but different values and different storage. So I’ve checked the table oc_storage

+--------------------------------------------+------------+-----------+--------------+
| id                                         | numeric_id | available | last_checked |
+--------------------------------------------+------------+-----------+--------------+
| local::/nextcloud_data/                    |         25 |         1 |         NULL |
| home::TRASH                                |         88 |         1 |         NULL |
| 90                                         |         91 |         1 |         NULL |
| 80                                         |         92 |         1 |         NULL |
| 78                                         |         93 |         1 |         NULL |
| 94                                         |         95 |         1 |         NULL |
| 70                                         |         96 |         1 |         NULL |
| 79                                         |         97 |         1 |         NULL |
| 73                                         |         98 |         1 |         NULL |
...

The file on the filesystem is located at /nextcloud_data/TRASH/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README

It seems that there are duplicate entries on oc_filecache ? One entry for the root of all files ( = /nextcloud_data/ ) and also for the the user TRASH ?

MariaDB [nextcloud_db]> SELECT COUNT(*) FROM oc_filecache WHERE storage = 25;

+----------+

| COUNT(*) |

+----------+

| 3291644 |

+----------+

MariaDB [nextcloud_db]> SELECT COUNT(*) FROM oc_filecache WHERE storage = 88;
+----------+
| COUNT(*) |
+----------+
|   379704 |
+----------+

Also, what are the other values in oc_storage? For example id: 90, numeric_id 91 ?

Is this the first time you’ve seen this error? (Y/N): Y

Have I understood the following correctly?
files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README
→ does not exist in the file system but have positive timestamp
TRASH/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README.
→ does exist in the file system but have got negative timestamp.

Maybe there is a problem with occ files:scan because of your selection with --path. Is it possible to re-scan the full user XYZ with occ files:scan XYZ? Have you test it?

It may also be useful to delete all the faulty files, rescan them and possibly restore files from the backup. Re-scan with 3 million files hopefully no problem. Maybe you can use a test system first.

It’s the same file.

$find /nextcloud_data/ -path "*/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README"
/nextcloud_data/TRASH/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README

One entry has the username included in the path - the entry with storage 25
the other not - the entry with storage 88.

The owner of the file is “TRASH”, not XYZ. XYZ is part of the path.

I’ll rescan with user instead of the path.
EDIT: No difference.

TRASH/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README.
full path: /nextcloud_data/TRASH/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README
That is ok if TRASH is a username in Nextcloud.

files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README
full path? /nextcloud_data/files/XYZ/tmp/apache_php_win7/PHP/tmp/PEAR-1.9.0/README

I think that makes no sense.
On my installation is no path /nextcloud_data/files . There is e.g. files_external or the usernames e.g. TRASH.

Can you check it?
I think the files in /nextcloud_data/files does not exist in the filesystem but in the database. It could be that the scan does not work at all because it is outside the users. I think all files in the database with /files/... are wrong.

No, the path /nextcloud_data/files does not exist.

Do you have the entry in your database?

+--------------------------------------------+------------+-----------+--------------+
| id                                         | numeric_id | available | last_checked |
+--------------------------------------------+------------+-----------+--------------+
| local::/nextcloud_data/                    |         25 |         1 |         NULL |

nextcloud_data is the folder where all files of the users are stored.

there are several entries starting with files/% in oc_filecache with different storage ids …

if you connect same external storage for multiple users, oc_filecache records for each user will be created (at least it was reported earlier, not sure still the case).

occ files:scan does not remove invalid entries from oc_filecache table. May be you want run occ files:cleanup as well

https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/occ_command.html#file-operations

It’s not an external storage. It’s the local storage. That’s the only external storage I have:

occ files_external:list
+----------+-------------+---------+---------------------+-------------------------------------------+---------+------------------+-------------------+
| Mount ID | Mount Point | Storage | Authentication Type | Configuration                             | Options | Applicable Users | Applicable Groups |
+----------+-------------+---------+---------------------+-------------------------------------------+---------+------------------+-------------------+
| 8        | /Scanner    | Local   | None                | datadir: "\/scanner\/"                    |         | All              |                   |
+----------+-------------+---------+---------------------+-------------------------------------------+---------+------------------+-------------------+

I did already run occ files:cleanup … did not make any difference in oc_filecache or oc_storage.

occ files:cleanup
0 orphaned file cache entries deleted
0 orphaned mount entries deleted

I noticed, that the entry starting with files/% has the correct timestamp, the entry starting with the username doesn’t.

SELECT st.id, COUNT(*) FROM oc_filecache as fc join oc_storages as st on fc.storage = st.numeric_id WHERE path LIKE 'files/%' GROUP BY fc.storage;
+--------------------------------------------+----------+
| id                                         | COUNT(*) |
+--------------------------------------------+----------+
| home::TRASH                                |   379697 |
| ....
+--------------------------------------------+----------+


MariaDB [nextcloud_db]> SELECT st.id, COUNT(*) FROM oc_filecache as fc join oc_storages as st on fc.storage = st.numeric_id WHERE path NOT LIKE 'files/%' GROUP BY fc.storage;
+--------------------------------------------+----------+
| id                                         | COUNT(*) |
+--------------------------------------------+----------+
| local::/nextcloud_data/                    |  3291644 |
| home::TRASH                                |        7 |
| ....
+--------------------------------------------+----------+

in local::/nextcloud_data/ no path starts with files/%
My guess, the faulty entries, which don’t get updated with the occ files:scan command are the ones starting with username.
I’ll play around and check if I can confirm this.

1 Like

Further investigations:

if I share the file with duplicate entry I get the fileid without the username in the path:
https://nextcloud/index.php/f/3726043

if I change mtime of the physical file, the entry without the username in the path gets updated.

If I create new files, the path does not contain the username.
There is only a single entry for the file.

This strengthens my assumption, that the entries starting with username are garbage. Can someone confirm this?