How to delete previews? (S3 primary)

It just occurred to me that with S3 as the primary storage there is no way to delete the app folder. ./occ has a delete preview command but it states it’s for a version older then nextcloud 12.

So… would I need to parse the database, find the preview files and delete them with a script?

You will find the previews under DATADIRECTORY//appdata_.../preview.

Don’t see it there. Are you sure?

user@node:/var/www/data# ls -l
total 64804
drwxr-xr-x 4 www-data www-data 4096 Oct 28 08:39 cache
drwxr-x— 3 www-data www-data 4096 Oct 27 06:26 news
-rw-r----- 1 www-data www-data 66335354 Oct 29 04:17 nextcloud.log

Are you sure that this is correct data directory? You have no index.html, appdata_xxxxx and user Folders (except if cache and news are NC user names).
Check you config.php:

grep datadirectory /var/www/nextcloud/config/config.php | cut -d "'" -f4

Yes, that’s exactly the folder. It’s interesting that your user folders are not listed in your directory too. My directory looks like this:

DATADIRECTORY/user-1
             /user-2
             /user-3
             /appdata_...
             /news
             /updater_backup

Maybe the directory structure varies a little bit of you use S3 as a primary storage?!
Where are your user directories located?

Yup.

/var/www/html# grep datadirectory /var/www/html/config/config.php | cut -d “’” -f4
/var/www/data

├── [ 40K] urn:oid:52425
├── [ 54K] urn:oid:52427
├── [ 51K] urn:oid:52426
├── [ 38K] urn:oid:52428
├── [ 43K] urn:oid:52431
├── [ 44K] urn:oid:52430
├── [ 46K] urn:oid:52432
├── [ 36K] urn:oid:52429
├── [ 69K] urn:oid:52436
├── [ 45K] urn:oid:52435
├── [ 49K] urn:oid:52434
├── [ 44K] urn:oid:52433
├── [ 72K] urn:oid:52438
├── [ 30K] urn:oid:52437
├── [ 44K] urn:oid:52439
├── [ 53K] urn:oid:52441
├── [ 48K] urn:oid:52440
├── [ 41K] urn:oid:52443
├── [ 54K] urn:oid:52442
├── [ 48K] urn:oid:52446
├── [ 49K] urn:oid:52445

0 directories, 47710 files

The command used here was rclone tree -t --human s3:/bucket/ but nextcloud doesn’t use rclone, it’s just an easy way to access the bucket.

Well this is irritating. I would indeed need to parse the database and delete files via script.

(86,1,‘appdata_oc0122siec7p/preview/18/500-500-max.png’,

urn:oid:86 is the preview image.

1 Like

@Paradox55
that’s why i’m not a fan of S3 as primary storage. until someone assures me that the database is not only place where the relation between filename and S3 object is stored.

As long as you backup the database it’s fine. You can also use a HA database server so changes are synced between both servers instantly.

S3 is significantly better as far as performance goes as you’re removing the filesystem from the equation. This becomes even more apparent on fuse based file systems, which are the go-to for any kind of cluster storage.

Parsing the database is still not ideal. I’m going to take a look at the source code and see how nextcloud handles removing previews when a user is deleted from the system.

Because if that code doesn’t exist then nextcloud is not a production ready system as far as I’m concerned.

Edit: To expand on the above, it’s because a single user can use over 100GB+ in image previews depending on your servers preview settings. Some obnoxious users might even rack up a 1+ TB depending on how many images they have if you allow a lot of storage per user. If those previews aren’t deleted when a user is removed from the system… well, on a highly active nextcloud server - say Hetzner’s - you’re looking at a lot of data being left behind along with a ballooned mysql database.

1 Like

Not sure about this, but previews config change definitely needs some action to do:

Thanks but… that doesn’t help.

Appreciate the effort though!

1 Like

Hi were you able to figure out how to delete files from S3 when you delete it from your nextcloud dashboard

Yup!

Allow me to explain the current solution for this problem. You get to go through the oc_filecache table and parse every filename then you have to take every preview and make sure you don’t remove the theme images. Once you do that you have to add it to a script that goes into your S3 bucket and manually removes it.

Since each urn: object is unique you also have to parse that.

Enjoy!

How to go through oc_filecache?

Open the mysql database table.

but thats a lot of manual work and everytime i delete a file/folder this step would need to be done?

That’s the step I use. If there is another way of doing it and you find it let me know.