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. PhoneGap在iOS开发下的注意事项

    敏捷个人应用主要是在Andorid下开发,发布的也主要是Andorid.之所以没有急着退出iOS版本,主要是因为开发iOS需要iOS的开发环境,发布还需要开发者账号,这些都需要资源或钱.而最近越来越多 ...

  2. Theano入门神经网络(三)

    附录一个:Keras学习随笔 http://blog.csdn.net/niuwei22007/article/details/49045909 参考 <Python Machine Learn ...

  3. JavaScript可否多线程? 深入理解JavaScript定时机制

    JavaScript的setTimeout与setInterval是两个很容易欺骗别人感情的方法,因为我们开始常常以为调用了就会按既定的方式执行, 我想不少人都深有同感, 例如 setTimeout( ...

  4. HT for Web基于HTML5的图像操作(二)

    上篇介绍了HT for Web采用HTML5 Canvas的getImageData和setImageData函数,通过颜色乘积实现的染色效果,本文将再次介绍另一种更为高效的实现方式,当然要实现的功能 ...

  5. C#实现WinForm DataGridView控件支持叠加数据绑定

    我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...

  6. .Net语言 APP开发平台——Smobiler学习日志:仿12306的APP登陆界面

    最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便 一.目标样式 我们要实现上图中的效果,需要如下的操作: 1.从工具栏上的”Smobil ...

  7. LINQ的Union方法

    2个集合合并,有相同的只取中其一个: source code: , , }; , , }; var result = a.Union(b); result.ForEach(delegate (int ...

  8. 【C#】使用IExtenderProvider为控件添加扩展属性,像ToolTip那样

    申明: - 本文适用于WinForm开发 - 文中的“控件”一词是广义上的说法,泛指包括ToolStripItem.MenuItem在内单个界面元素,并不特指继承自Control类的狭义控件 用过To ...

  9. Bootstrap学习笔记系列6-----Bootstrap文本显示

    通过对文本或者链接添加下面的类,会使其展示不同的颜色,如果文本是个链接,鼠标移动到文本上,颜色会变暗. text-muted柔和的文本(深色) text-primary 表示基础的文本(蓝色) tex ...

  10. 炉石传说 C# 开发笔记(BS模式Demo)

    原来这个项目,一直想做成CS模式的,BS模式对于炉石这样的游戏来说比较困难. 暴雪到现在也只出了 Windows 和 iPad版本的炉石,最大的问题还是在于如何在小屏幕下,实现最佳的客户体验. Win ...