When scanning files with occ - how to keep file's modification date


recently, my NextCloud crashed. Instead of looking for the problem and its possible solution (as I have done multiple times in the past), I now want to just restore all the user files onto a new NextCloud installation. The installation of NextCloud v25.0.3.2 via NextCloudPi v1.51.0 went fine, so far.

My old files are fortunately stored below a ncdata folder on an external SSD which I have now plugged to the newly installed NextCloud device. And moved into a backup folder.

here is part of a backup folder:

-rw-r--r-- 1 www-data www-data  268724  9. Jun 2021  comm_email.c
-rw-r--r-- 1 www-data www-data    6482 27. Dez 2020  comm_email.py
-rw-r--r-- 1 www-data www-data  248106 16. Jan 2022  comm_signal.c
-rw-r--r-- 1 www-data www-data    4536 16. Jan 2022  comm_signal.py
-rw-r--r-- 1 www-data www-data     506 14. Nov 2018  contacts_individual.ini
-rw-r--r-- 1 www-data www-data    1878 14. Apr 2020  contacts.ini

the file creation dates are correct.

Now, the new ncdata and ncdatabase folders were at first empty and, via configuration, ready to be used wihtin NextCloud. I did the following:

  1. I used bash’s cp command to transfer the old user folders from the backup location to below ncdata/data/. About 7 GB of data.

  2. I issued the following command to scan the newly tranferred files into the NextCloud database: sudo -u www-data php /var/www/nextcloud/occ files:scan --all . This worked fine.

Looking into the respective folder now, after occ 's scan command has done its job, I see:

-rw-r--r-- 1 www-data www-data  268724  7. Feb 23:13 comm_email.c
-rw-r--r-- 1 www-data www-data    6482  7. Feb 23:13 comm_email.py
-rw-r--r-- 1 www-data www-data  248106  7. Feb 23:13 comm_signal.c
-rw-r--r-- 1 www-data www-data    4536  7. Feb 23:13 comm_signal.py
-rw-r--r-- 1 www-data www-data     506  7. Feb 23:13 contacts_individual.ini
-rw-r--r-- 1 www-data www-data    1878  7. Feb 23:13 contacts.ini

=> all the file’s creation dates have been set to the date where the occ command did its job.

This is not what I intended to happen, as I want to revover the files and keep their modification dates. This is important in order to not override changes different users could have made during the current downtime of the NextCloud service.

Looking up the documentation for the scan function of occ shows that there is no option to tell NextCloud to actually keep the existing modification dates.

Is there any way to restore the original file modification dates of my files? Shouldn’t there be an option like this to do that?


I think that was the problem. You can better use rsync -a for that

rsync -a
archive mode; equals -rlptgoD (no -H,-A,-X)

Maybe you can use the command without deleting the destination first and rsync repair it for you. Maybe not. Make a backup first. Use / hat both paths at the end like my example. Then only the content is copied and you have got no directory-in-directory problem.

rsync -av /path/to/backup/ /path/to/ncdata/data/

-v verbose mode (so you can see what happens)

Hi @devnull , thanks for your quick reply.

I had been looking up the possible options for cp and found this:

              preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes:  context,
              links, xattr, all

thus, I was sure that by omitting the --preserve option, I would automatically choose these defaults, which seem to include timestamps alongside ownership and mode. I should just have used --preserve with cp, I guess.

I now have everything scanned and the modification dates show correctly within the user’s data folders as well as within the web interface. Great.

One last question regarding the last steps to become fully operational, again: I want to now re-connect all NextCloud clients to the new server. In order to correctly trigger file updates in all clients I would do the following:

  • remove the system files within the NextCloud base folders of each client (these are .sync_cd5b3dc9e7eb.db, .sync_cd5b3dc9e7eb.db-shm and .sync_cd5b3dc9e7eb.db-wal) and then…

  • re-connect each client to the new NextCloud service. with new password which would have to be changed by each user.

I would expect that each NextCloud client would thus try to synchronize the locally existing files with the server’s files and recognize only the recently modified or new files for synchronization.

Or should I keep the system files within the client’s base folders before connecting to the new server? This might cause problems, right?