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. ATL是如何实现线程安全的引用计数和多线程控制的

    ATL是如何实现线程安全的引用计数和多线程控制的 正如标题所示,这是我经常被问到的一个问题,而每次我都从头开始给人说一次,其实说来过程理解起来的确有点复杂. 我们的每一个ATL Server Obje ...

  2. Windows Azure Web Site (7) Web Site配置

    <Windows Azure Platform 系列文章目录> 在上一章内容中,我们已经部署了Azure WebSite.我们可以在Web Site配置页面进行配置.如下图: 另外,我们还 ...

  3. 帮助你提高排版技巧的18个 PS 文字特效教程

    Photoshop 文字特效教程对于学习基础的和高级的排版思维有很大的帮助.在这篇文章中,你会发现一组最新发布的文字效果教程.这些高品质的 Photoshop 教程可以帮助你设计出惊人的2D,3D,木 ...

  4. 前端工程化开发之yeoman、bower、grunt

    上两遍文章介绍了前端模块化开发(以seaJs为例)和前端自动化开发(以grunt为例)的流程,参见: http://www.cnblogs.com/luozhihao/p/4818782.html ( ...

  5. var 的使用

    List<Enterprise> epList = ViewBag.epList; foreach (var item in epList){ //todo ... } 当 List< ...

  6. iOS 阶段学习第十天笔记(字符串操作)

    iOS学习(C语言)知识点整理 一.字符串的操作 1)字符串的存储,字符数组,在堆里面申请内存空间. 实例代码: #include <stdlib.h> #include <stri ...

  7. win10下iis部署asp.net core rtm

    随着ASP.NET Core 1.0 rtm的发布,网上有许多相关.net core 相关文章,今刚好有时间也在win10环境上搭建下 ASP.NET Core的部署环境,把过程记录下给大家. 1. ...

  8. SharedPreferences写入和读出数据

    Android中有很多方法存储数据,如SharedPreferences.SQLite数据库等.简单数据的存储适用SharedPreferences. 本文使用SharedPreferences写入和 ...

  9. 基于TCP和多线程实现无线鼠标键盘-InputMethodManager

    为了实现无线键盘的功能,使用了InputMethodManager弹出软键盘. // 弹出软键盘 public void pop_keyboard(){ imm = (InputMethodManag ...

  10. freemarker:简介

    Apache FreeMarker模板引擎:Java库来生成文本输出(HTML网页,电子邮件,配置文件,源代码,等等)基于模板和变化的数据.模板都写在FreeMarker模板语言(FTL),这是一个简 ...