For umbraco 7+ (currently last release 7.7.7) i made this script to empty both media and document recycle bin:
DELETE FROM cmsPreviewXml WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM cmsContentVersion WHERE ContentId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM cmsDocument WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM cmsTagRelationship WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM cmsContentXML WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM cmsContent WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM cmsPropertyData WHERE contentNodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM umbracoDomains WHERE domainRootStructureID IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM umbracoUser2NodePermission WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM umbracorelation WHERE parentId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM umbracorelation WHERE childId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
DELETE FROM umbracoredirecturl WHERE contentKey IN (SELECT uniqueID FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
ALTER TABLE `umbraconode` DROP FOREIGN KEY `umbraconode_ibfk_1`;
DELETE FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20);
ALTER TABLE `umbraconode` ADD CONSTRAINT `umbraconode_ibfk_1` FOREIGN KEY (`parentID`) REFERENCES `umbraconode`(`id`);
I noticed some errors related to cmsContent what was about to be deleted but had a foreign key constrain to a media item, after emptying the media recycle bin from the backoffice this code worked great on Umbraco v7.12.3.
Edit:
Also for 7.8+ the umbracoUser2NodePermission-row can be changed to
DELETE FROM umbracoUserGroup2NodePermission WHERE nodeId IN (SELECT id FROM umbracoNode WHERE (path LIKE '%-21%' AND id!=-21) OR (path LIKE '%-20%' AND id!=-20));
BEGIN TRAN
-- I recommend figuring out what is causing any constraint issues instead of turning the constraint off, but thought I'd include it.
--ALTER TABLE umbracoNode NOCHECK CONSTRAINT FK_umbracoNode_umbracoNode_id
DECLARE @Nodes TABLE (NodeId int)
INSERT INTO @Nodes (NodeId)
SELECT id
FROM umbracoNode
WHERE [path] like '%-20,%'
AND id !=- 20
-- Content recycle bin only
AND nodeObjectType = 'C66BA18E-EAF3-4CFF-8A22-41B16D66A972'
delete from umbracoDomain where id in (select NodeId from @Nodes);
delete from cmsContentNu where nodeId in (select NodeId from @Nodes)
delete from umbracoRedirectUrl where contentKey in (select uniqueId from umbracoNode where id in (select NodeId from @Nodes))
delete from cmsTagRelationship where nodeId in (select NodeId from @Nodes)
delete from umbracoContentSchedule where nodeId in (select NodeId from @Nodes)
delete from umbracoDocumentCultureVariation where nodeId in (select NodeId from @Nodes)
delete from umbracoRelation where parentId in (select NodeId from @Nodes) or childId in (select NodeId from @Nodes)
delete from umbracoUserGroup2NodePermission where nodeId in (select NodeId from @Nodes)
delete from umbracoUserStartNode where startNode in (select NodeId from @Nodes)
update umbracoUserGroup set startContentId = null where startContentId in (select NodeId from @Nodes)
delete from umbracoPropertyData where versionId in (select id from umbracoContentVersion where nodeId in (select NodeId from @Nodes))
delete from umbracoDocumentVersion where id in (select id from umbracoContentVersion where nodeId in (select NodeId from @Nodes))
delete from umbracoContentVersion where nodeId in (select NodeId from @Nodes)
delete from umbracoDocument where nodeId in (select NodeId from @Nodes)
delete from umbracoContent where nodeId in (select NodeId from @Nodes)
delete from umbracoNode where id in (select NodeId from @Nodes)
delete from umbracoUser2NodeNotify where nodeId in (select NodeId from @Nodes)
-- Any custom tables that you have that might need to be cleaned up too.
DELETE FROM @Nodes
--ALTER TABLE umbracoNode CHECK CONSTRAINT FK_umbracoNode_umbracoNode_id
ROLLBACK TRAN
Running this in a transaction allows you to see what is about to happen w/o actually deleting anything. Once you are satisfied with it just change that last line (ROLLBACK TRAN) to COMMIT TRAN
I've also toyed with deleting only items that have been in the recycle bin > 1 month and doing this with a scheduled task. That would change your selection of the nodes to something like:
SELECT id
FROM umbracoNode u
join umbracoLog l on l.NodeId = u.id
WHERE u.[path] like '%-20,%'
AND u.id !=- 20
AND u.nodeObjectType = 'C66BA18E-EAF3-4CFF-8A22-41B16D66A972'
AND l.logHeader = 'Delete'
AND l.Datestamp < DateAdd(month, -1, GetDate())
If you do have constraint errors I've used a cursor to iterate over each of the nodes and run the delete statements on them individually. That helps find any nodes that are causing issues. I can probably provide that too if you need it.
I ran into this too, but I was able to work around it. There are a couple key things to note.
Click recycle bin in navigation on the left to reach a list view that can be used to delete content in batches.
Timeout errors can be caused by having too many versions of a node. A plugin like UnVersion can be used to remove old versions so that the node can be deleted.
I've posted about this in more detail on another thread for this same issue. Feel free to look there for more details on how I resolved this.
I've run into this problem in the past, and the most tedious way of doing it is to manually empty 5-10 nodes at a time. If there is a folder, empty only that folder.
The reason being that the timeout will kick in for larger batches of cleaning.
The solution proposed by Alex, to increase the database timeout, looks like a cool one, but I assume for very large batches it could take close to an hour.
Unable to empty recycle bin
Hi our! :)
Currently got a problem where i can't empty my recycle bin, it just gives me an "Timeout error" with "500 (Internal Server Error)"
The site did run Umbraco 7.5.6 so i tried to upgrade to Umbraco 7.5.14, but it didn't help.
It's both content and media recycle bin that i can't empty.
I'm trying to empty those since the database is using 2.2GB, and i have UnVersion installed :)
Hi Anders
Maybe it will help you, really nice SQL query for clearing Umbraco database, it can reduce size drastically:
https://gist.github.com/dampee/a8ead728165b16d49c00
Thanks,
Alex
Hi Alex,
Thanks for your time! :)
I will try run that script, currently i have tried this one,
https://gist.github.com/genckastrati/0e7f7ae6156647e00a56eb5ef403166d
But it didn't allowed me to empty the recycle bins :(
You are welcome, also can you check what is timeout for sql server operations?
Try to check it with MSSQL management studio.
Hope it will help,
Alex
For umbraco 7+ (currently last release 7.7.7) i made this script to empty both media and document recycle bin:
Backup your DB before trying it.
Thanks for sharing this!
I noticed some errors related to cmsContent what was about to be deleted but had a foreign key constrain to a media item, after emptying the media recycle bin from the backoffice this code worked great on Umbraco v7.12.3.
Edit: Also for 7.8+ the umbracoUser2NodePermission-row can be changed to
// m
Is this script working for the latest Umbraco version?
Can anyone help with a version to Umbraco 8?
Here's a version that I use for v8.
Running this in a transaction allows you to see what is about to happen w/o actually deleting anything. Once you are satisfied with it just change that last line (ROLLBACK TRAN) to COMMIT TRAN
I've also toyed with deleting only items that have been in the recycle bin > 1 month and doing this with a scheduled task. That would change your selection of the nodes to something like:
If you do have constraint errors I've used a cursor to iterate over each of the nodes and run the delete statements on them individually. That helps find any nodes that are causing issues. I can probably provide that too if you need it.
I ran into this too, but I was able to work around it. There are a couple key things to note.
I've posted about this in more detail on another thread for this same issue. Feel free to look there for more details on how I resolved this.
Hi everyone,
I've run into this problem in the past, and the most tedious way of doing it is to manually empty 5-10 nodes at a time. If there is a folder, empty only that folder.
The reason being that the timeout will kick in for larger batches of cleaning.
The solution proposed by Alex, to increase the database timeout, looks like a cool one, but I assume for very large batches it could take close to an hour.
/Peter
is working on a reply...