Emptying the Second Stage Recycle Bin in SharePoint 2007

 

Look in your second stage recycle bin in SharePoint 2007.  If you see lots of items that are older than the configured policy (default is 30 days), then there are one of a few things happening in your environment.  Your recycle bin cleanup job might be disabled, or you might be running into a bug in SharePoint where it cannot clean the items up because there are too many of them or the items are too large.

Note that this problem does not exist for SharePoint 2010.

What is the Second Stage Recycle Bin?

The Recycle Bin was introduced in SharePoint 2007 as a way for people to delete items with the ability to undo that action at some later point.  Pretty self-explanatory, it’s just like the recycle bin in Windows.  This recycle bin is commonly referred to as the user recycle bin, because the user has the ability to delete and restore items to the recycle bin.

Notice the verbiage at the top of that image that says items more than 30 days old are automatically deleted.  When you delete the items from the recycle bin, they aren’t really deleted.  They go into what is called the second stage recycle bin.  This recycle bin is only accessible by site collection administrators, giving them the ability to restore items.  You can see this in the Site Collection Recycle Bin.

Here, we see that our item is in the End User Recycle Bin.  If we delete the item from here or if we click the “Empty Recycle Bin” button, our item is not deleted, it instead ends up in the “Deleted from end user Recycle Bin” view, which is what is also called the second-stage recycle bin.

If you manually delete an item here, it is immediately deleted.  By deleted I mean that the item is deleted from the content database.  If an item is left in here for 30 days (the default), then the recycle bin cleanup job will permanently delete the items from the content database.

Why Is My Second Stage Recycle Bin Not Emptying?

Simply put, the recycle bin cleanup job in SharePoint 2007 is not efficient and can time out if there are too many items or if the items are sufficiently large.  Sorry, I don’t have hard limits to share as there are a lot of variables at play.  The symptom that you may see is that even though you have the timer job configured to clean the items up, they remain in the second stage recycle bin.

If you want to see the problem in action, then try this PowerShell script.  I am leveraging the Get-SPWeb cmdlet from PowerShell.nu’s MOSS 2007 Script Collection.

function Add-LotsOfAnnouncements2()
{
$OpenWeb = Get-SPWeb http://w2k3mossx64 $Announcement = $OpenWeb.Lists["Announcements"] for($j=0;$j -lt 1000000000;$j++)
{
$t = "Item " + $j;
$NewItem = $Announcement.Items.Add()
$NewItem["Title"] = $t
$NewItem["Body"] = "item"
$NewItem["Expires"] = (Get-Date).AddDays(10)
$NewItem.Update()
$toss = $NewItem.Recycle()
} $OpenWeb.Dispose() }

This adds a new item, then immediately sends it to the recycle bin.  Let it run for while, and you will see items piling up in the end user recycle bin.  At some later point, empty the end user recycle bin, moving the items to the second stage recycle bin.  After the amount of time configured in your policy expires, the recycle bin timer job will attempt to delete the items and will time out.

The problem is discussed in the post Deleting Very large objects from the second stage recycle bin.  While we are deleting many, many objects instead of very large objects, the symptoms are the same.  Note that this problem does not exist for SharePoint 2010, this only pertains to SharePoint 2007.

Check the Recycle Bin Cleanup Job

You can check the status of the Recycle Bin cleanup job in Central Administration > Operations > Timer Job Definitions.  This is configured per web application.  You can see the list of recycle bin jobs and quickly see if they are enabled or not.

Click on one of the entries for Recycle Bin that corresponds to your web application, and you will see the last run date.

This timer job The job-recycle-bin-cleanup job is configured to run daily between 11pm and 6am.  You can check this using stsadm.exe:

stsadm -o getproperty -pn job-recycle-bin-cleanup -url http://moss

The output will be something like the following.

<Property Exist="Yes" Value="daily between 22:00:00 and 06:00:00" />

There are examples of getting and setting different values for this timer job in the online documentation.

Configure Policy for the Recycle Bin for the Web Application

The recycle bin policy is configured at the web application level.  This is important to emphasize because changes you make here affect all site collections within the web application.  You can find the configuration in Central Administration > Application Management > Web Application General Settings, scroll to the bottom of the page.

The default is to delete items in the recycle bin after 30 days, with 50% of the live site quota for second stage deleted items.  If you are running into the problem where items are piling up in the second stage recycle bin, you should decrease this number so that items do not live in the recycle bin for so long.  This decreases the number of items that need to be deleted at a time.

If you cannot decrease this number, then a workaround is to clean up the items manually.  You can do this with a custom timer job, a custom executable that is scheduled to run periodically, or some other process.  Below I show a PowerShell script that will empty the items in the second stage recycle bin.

To avoid having a lot of items in the second stage recycle bin, another option is to disable the second stage recycle bin by choosing the “Off” radio button.  Be aware that this will turn the second stage recycle bin off for the entire web application.  When you turn the second stage recycle bin off, the items will be immediately purged from the database, there is no undo operation here.  Remember that this applies for all site collections in the web application, it is not a site-collection level setting, so keep that in mind if you are concerned about losing data.

Impact of Quotas on the Recycle Bin

The second stage recycle bin is configured by default to use 50% of a site’s quota.  I applied a quota template to my site before running the above PowerShell script, and received this error once my site reached its quota.

"Your changes could not be saved because this SharePoint Web site has exceeded the storage quota limit.  You must save your work to another location.  Contact your administrator to change the quota limits for the Web site."

Once you reach quota, you can also receive errors while trying to delete items from the second stage recycle bin.  The workaround here is to either increase the quota temporarily, or to disable the site quota.  Once you’ve increased the quota or disabled it, you can then perform deletes in most cases.

PowerShell Script to Clean Up Second Stage Recycle Bin

If you went through the steps above and confirmed you have the problem outlined above, then you can clean the recycle bin manually before addressing the problem (reducing the length of time, disabling the second stage recycle bin, deleting without sending to the recycle bin by using the server side object model).  You can clean the items manually, likely one at a time to avoid timeouts and exceptions, or you can use a script to automate the task such as the PowerShell script below.

param([string]$Url, [switch]$help)

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

function GetHelp()
{
$HelpText = @" DESCRIPTION:
NAME: Remove-SPSiteSecondStageRecycleBin
Empties the second-stage recycle bin for a Microsoft.SharePoint.SPSite Collection PARAMETERS:
-url Url to SharePoint Site Collection SYNTAX: Remove-SPSiteSecondStageRecycleBin -url http://moss Empties the second stage recycle bin for the SiteCollection. Remove-SPSiteSecondStageRecycleBin -help Displays the help topic for the script "@
$HelpText
} function Remove-SPSiteSecondStageRecycleBin([string]$url)
{
$siteCollection = New-Object Microsoft.SharePoint.SPSite($url); $recycleQuery = New-Object Microsoft.SharePoint.SPRecycleBinQuery;
$recycleQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin;
$recycleQuery.OrderBy = [Microsoft.SharePoint.SPRecycleBinOrderBy]::Default; $recycledItems = $siteCollection.GetRecycleBinItems($recycleQuery); $count = $recycledItems.Count; for($i = 0; $i -lt $count; $i++)
{
$g = New-Object System.Guid($recycledItems[$i].ID);
$recycledItems.Delete($g);
} $siteCollection.Dispose()
} if($help) { GetHelp; Continue }
if($url) { Remove-SPSiteSecondStageRecycleBin -url $url }

This is pretty straightforward.  Rather than try to lock the table and delete all of the items, this code simply iterates the list one by one and deletes each item.  I tested it by deleting items and emptying the recycle bin both as the same user, then deleting items as one user and emptying the recycle bin as another, both worked as expected without incident.

Resources

Powershell Tutorial - Conditional Logic Using Loops

Job-recycle-bin-cleanup: Stsadm property (Office SharePoint Server)

Deleting Very large objects from the second stage recycle bin

PowerShell.nu’s MOSS 2007 Script Collection

SharePoint2007:解决第二回收站大数据无法删除问题的更多相关文章

  1. mysql大数据表删除操作锁表,导致其他线程等待锁超时(Lock wait timeout exceeded; try restarting transaction;)

    背景: 1.有一个定时任务,每10分钟入一批统计数据: 2.另一个定时任务,每天定时清理7天前数据,此定时任务每天01:18:00执行: 现象: 每天01:20:00的统计数据入库失败,异常信息如下, ...

  2. SQL Server百万级大数据量删除

    删除一个表中的部分数据,数据量百万级. 一般delete from 表 delete from 表名 where 条件: 此操作可能导致,删除操作执行的时间长:日志文件急速增长: 针对此情况处理 de ...

  3. 解决Mysql导入大数据出现gone away的问题

    在用Mysql Yog或者PHPMyadmin等工具导入数据量大的sql文件时,会提示“gone away”,那么如何处理这个问题尼? 在Mysql对应的配置文件中my.ini文件中加入以下配置: # ...

  4. 操作XmlDocument时,出现"System.OutOfMemoryException"异常,如何解决加载大数据的情况?

    System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.at System.St ...

  5. POI读写大数据量excel,解决超过几万行而导致内存溢出的问题

    1. Excel2003与Excel2007 两个版本的最大行数和列数不同,2003版最大行数是65536行,最大列数是256列,2007版及以后的版本最大行数是1048576行,最大列数是16384 ...

  6. 网络编程基础【day09】:解决socket粘包之大数据(七)

    本节内容 概述 linux下运行效果 sleep解决粘包 服务端插入交互解决粘包问题 一.概述 刚刚我们在window的操作系统上,很完美的解决了,大数据量的数据传输出现的问题,但是在Linux环境下 ...

  7. Hadoop是一种开源的适合大数据的分布式存储和处理的平台

    "Hadoop能做什么?" ,概括如下: 1)搜索引擎:这也正是Doug Cutting设计Hadoop的初衷,为了针对大规模的网页快速建立索引: 2)大数据存储:利用Hadoop ...

  8. 大数据技术 - 为什么是SQL

    在大数据处理以及分析中 SQL 的普及率非常高,几乎是每一个大数据工程师必须掌握的语言,甚至非数据处理岗位的人也在学习使用 SQL.今天这篇文章就聊聊 SQL 在数据分析中作用以及掌握 SQL 的必要 ...

  9. 大数据计算新贵Spark在腾讯雅虎优酷成功应用解析

    http://www.csdn.net/article/2014-06-05/2820089 摘要:MapReduce在实时查询和迭代计算上仍有较大的不足,目前,Spark由于其可伸缩.基于内存计算等 ...

随机推荐

  1. 初探JavaScript(一)——也谈元素节点、属性节点、文本节点

    Javascript大行其道的时候,怎么能少了我来凑凑热闹^_^ 基本上自己对于js的知识储备很少,先前有用过JQuery实现一些简单功能,要论起JS的前世今生,来龙去脉,我就一小白.抱起一本< ...

  2. Kettle实现MapReduce之WordCount

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 欢迎转载 抽空用kettle配置了一个Mapreduce的Word count,发现还是很方便快捷的,废话不多说 ...

  3. mysql插入日期 vs oracle插入日期

    今天做oracle日期插入的时候突然开始疑惑日期是如何插入的. 用框架久了,反而不自己做简单的工作了.比如插入. 通常,新建一个表对象,然后绑定数据,前端form提交,后端getModel后直接mod ...

  4. Javascript动画效果(三)

    Javascript动画效果(三) 前面我们已经介绍了速度动画.透明度动画.多物体运动和任意值变化,并且我们在Javascript动画效果(二)中介绍到我们封装了一个简单的插件雏形,接下来我们对前面的 ...

  5. ASP.Net 获取服务器信息

    1: Response.Write("服务器机器名:" + Server.MachineName); 2: Response.Write("<br/>&quo ...

  6. HTTPS协议说明

    HTTPS协议说明 基本现在最安全的网络连接就是使用https了,http协议有几个不安全的地方: 传输信息是明文的. -- http的传输信息是明文的,基本网络劫持下就束手就擒了. 不能防止篡改. ...

  7. iOS平台快速发布HT for Web拓扑图应用

    iOS平台一直是封闭的生态圈,iOS开发者要缴纳年费加入开发者计划才可进行iOS平台的APP开发测试,所开发的APP需要上传到App Store经过苹果审核以后才可对外发布.如果要开发企业内部应用,则 ...

  8. [转] MySql 优化 大数据优化

    一.我们可以且应该优化什么? 硬件 操作系统/软件库 SQL服务器(设置和查询) 应用编程接口(API) 应用程序 ------------------------------------------ ...

  9. 在_Layout模版中使用@Styles.Render()没有效果

    刚才有测试一个功能,就是在_Layout母版中使用了@Styles.Render()时行Render样式文件,所有在此母版下的视图均没有应用到样式,没有效果.是什么原因? 经查证资料,原来Insus. ...

  10. cefglue埋坑记录

    很少写博客,写的不好,请多多包含,主要是记录工作中的一些问题,和园子里朋友一起讨论学习. 写埋坑记录之前,我先介绍下为什么会使用这个webkit内核的浏览器组件,我是wpf项目使用富文本编辑器,话说w ...