deleteAssets endpoint not deleting orphaned assets
I made a mistake which lead to many images being deleted from the file system (it turns out using ProtonDrive as one of your backups is less than ideal because it syncs from the cloud back to the client). I am trying to remove the assets from Immich that were accidentally deleted by using the deleteAssets endpoint. The API is returning 204 as expected, but when I check the repair admin page after running the script, it still lists many of the assets as still being orphaned.
I am hoping someone can help me figure out what to do. I thought maybe a job would have to be run after purging the assets, but my initial run of the script removed about 10k of the orphaned files, but it just does nothing with the remaining 70k orphaned files.
12 Replies
:wave: Hey @dotfortun3,
Thanks for reaching out to us. Please carefully read this message and follow the recommended actions. This will help us be more effective in our support effort and leave more time for building Immich :immich:.
References
- Container Logs:
docker compose logs
docs
- Container Status: docker ps -a
docs
- Reverse Proxy: https://immich.app/docs/administration/reverse-proxy
- Code Formatting https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline#h_01GY0DAKGXDEHE263BCAYEGFJA
Checklist
I have...
1. :ballot_box_with_check: verified I'm on the latest release(note that mobile app releases may take some time).
2. :ballot_box_with_check: read applicable release notes.
3. :ballot_box_with_check: reviewed the FAQs for known issues.
4. :ballot_box_with_check: reviewed Github for known issues.
5. :ballot_box_with_check: tried accessing Immich via local ip (without a custom reverse proxy).
6. :ballot_box_with_check: uploaded the relevant information (see below).
7. :ballot_box_with_check: tried an incognito window, disabled extensions, cleared mobile app cache, logged out and back in, different browsers, etc. as applicable
(an item can be marked as "complete" by reacting with the appropriate number)
Information
In order to be able to effectively help you, we need you to provide clear information to show what the problem is. The exact details needed vary per case, but here is a list of things to consider:
- Your docker-compose.yml and .env files.
- Logs from all the containers and their status (see above).
- All the troubleshooting steps you've tried so far.
- Any recent changes you've made to Immich or your system.
- Details about your system (both software/OS and hardware).
- Details about your storage (filesystems, type of disks, output of commands like fdisk -l
and df -h
).
- The version of the Immich server, mobile app, and other relevant pieces.
- Any other information that you think might be relevant.
Please paste files and logs with proper code formatting, and especially avoid blurry screenshots.
Without the right information we can't work out what the problem is. Help us help you ;)
If this ticket can be closed you can use the /close
command, and re-open it later if needed.I think I found the issue:
It looks like the deleted photos belong to a stack, so it won't delete due to the foreign key violation
Successfully submitted, a tag has been added to inform contributors. :white_check_mark:
I updated the script to search for assets where they are the primary asset of stack and then it will delete them before attempting to delete the asset from the DB
I think I got it working, but I had to delete it from the DB directly. No matter what I did, the deleteStacks endpoint returned 400 Bad Request
If someone can help me figure out if it's possible to delete stacks from the API, that would be great. I would like make a PR to the Remove offline files project
It should be, can you share your request payload for the deleteStacks API?
Sure! I can't show you an actual one because I deleted the stacks from the DB directly, but I can show you what it looks like with dummy data.
The weird part is that even though I deleted the stacks directly, it still isn't removing the assets when I make a call to delete an orphaned asset.
I forgot to mention the return code is 400 and it says I either do not have access, or it doesn't exist, but I was able to query the all stacks and then filter them with the known missing images
The logs keep looking like this:
Also, I dumped the entirety of my logs and uploaded them here: https://drive.proton.me/urls/9BYVJHQHPC#Q7HfpaHXWbI3
Proton Drive
Securely store, share, and access your important files and photos. Anytime, anywhere.
Ok, so a little more information. I think the assets were successfully deleted, but they still show in the repair page, but if I query the DB directly they are gone. The logs still keep saying they are queuing 78032 assets for deletion though.
Were the files deleted from the disk as well?
They were already deleted because I accidentally deleted them from the disk.
so to sum up:
1.) you use a "backup" service which syncs your photos both ways
2.) you deleted them on that cloud service which in turn deleted them on your local disk
3.) now you see errors in immich that those items no longer exist
is this correct?
just to clarify, the repair option will not "restore" those images
you need to restore those yourself, try checking if that cloud option has something to restore deleted files, that might be your best bet
other than that, try to write as little as possible to the disk your photos were on, every write could be on places where your photos were stored... your last option might be to try recovery tools to recover photos from that disk
of course, if you have actual backups of those photos and can restore them, that would be the best
@dotfortun3
Yeah that’s correct, I’m not trying to get them back, I was trying to fix Immich cause I know files deleted from the disk causes issues in Immich, so I was just trying to clean up the database before I restore them from my 2nd backup. I am basically trying to avoid wiping the Immich DB since there are still thousands of photos that have stuff like that associated with them.
But I’m trying to preserve as much as I can in terms of albums, likes, and comments
But also, my initial question was about getting 400 Bad Request from the assets/stacks when calling DELETE, it just kind involved me providing more information because I think it actually did delete the records from the DB, but the repair is still show 78k orphaned assets
https://discord.com/channels/979116623879368755/1357226144667271228/1357226144667271228