The ‘preview’ files folder somwhere below data dir is getting quite large. How can I clean up this folder, causing the previews to disappear, but be regenerated when necessary?
I tried the following:
remove the preview folder
-> this causes the previews to disappear without being regenerated, not good
remove the preview folder, then run occ
occ is not an option as my hosting company does not has posix tools enabled
Can I, somehowe, remove the preview folder, and cleanup the database, so that the files are generated when necessary?
Thanks
for example, can I remove the preview folder, and all references to it in the “filecache” table? (with “preview” in the path)?
I have done the following procedure with success:
backup everyting (datadir + database) before you attempt this
remove folder data/appdata_ocpb8d7vbr73/preview (appdata_ocpxxxxxxxx/preview)
(only the preview dir!)
on the database, execute:
delete from oc_filecache where path like ‘appdata_ocpb8d7vbr73/preview/%’;
Now the previews are gone freeing the diskspace. When a user visits the folder and diplays previews, the previews are regenerated for that folder.
Note that this slows down nextcloud significantly, until previews are generated again, i.e. when previewing a folder for the first time.
Note also that, while i have tested this procedure with nextcloud 12.0.3, it is most probably not supported by the Nextcloud team
2 Likes
I’m interested in that issue too.
Normally the preview images were deleted automatically when the originating file is deleted. This is the theory.
But if you have really a lot of files this does not work.
@rullzer @nickvergessen can you confirm the method of @Stijn_Haezebrouck ?
Or is there an easier way, e.g. an occ
command?
Thank you!
While it should work, no guarantees that it might not cause temporary troubles.
No, there is no “easy” way
Sanook
June 21, 2018, 10:14am
6
So it would be a nice extension to the occ files:cleanup
command.
Does this mean that the method of @Stijn_Haezebrouck is correct and the only way @nickvergessen ?
For anyone looking for a quick way to accomplish this via script, here’s what I use. Granted, it’s Docker, but you can modify as required.
#!/bin/bash
du -sm /data/docker/containers/nextcloud
docker exec --user www-data nextcloud php occ files:cleanup
docker exec --user www-data nextcloud php occ versions:cleanup
docker exec --user www-data nextcloud php occ trashbin:cleanup --all-users
rm -rf /data/docker/containers/nextcloud/apache/data/data/appdata_*/preview/*
docker exec nextcloud-mariadb /bin/bash -c "echo 'delete from oc_filecache where path like \"appdata_%/preview/%\";' | mysql -u nextcloud -pPASSWORD nextcloud"
du -sm /data/docker/containers/nextcloud
5 Likes
Since this here comes up as nr1 in search engines and is also used by copilot/gpt…
Nowadays step 3 in the procedure, ie the direct db manipulation, is better replaced by occ files:scan-app-data