SharePoint發行版本有SharePoint2003、SharePoint2007、Sharepoint 2010、SharePoint2013和SharePoint2016。SharePoint提供了功能強大的團隊協作環境,使得組織能夠在整個組織內部實現整合、組織、查找和提供 SharePoint站點。 最近,用戶提出數據庫大小太大,所以,希望把文件歸檔。至于歸檔,該怎么做呢? 正文 我們提出的解決方案,占用數據庫最主要的就是各種文檔,那就按照時間為限制,超過一年的文檔全部備份,由用戶的IT自行保存到他們的存儲中。 還好用戶的數據規模不是特別的大,我們使用程序來處理也不會特別的耗時。 ? 文檔庫 關于文檔庫處理起來比較容易,我們只需要用Windows 資源管理器視圖,把文檔先拷貝下來進行備份,然后再進行刪除就可以了。 ? 列表 列表處理起來,還是比較有難度的,我們需要把所有項目的列表附件都備份,然后進行刪除。 我們這里講的就是如何批量備份,至于刪除,只需要稍稍改一下下面的腳本,就可以了。 復制代碼 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#SharePoint variables $SiteUrl = "http://siteurl" $WebUrl = "weburl" $LibraryName = "listname" #Save Path $SavePath = "C:\ListBackup20200227" #Get SPSite $site= New-Object Microsoft.SharePoint.SPSite($SiteUrl) #Get SPWeb $Web = $site.OpenWeb($WebUrl) #Get SPList $List = $Web.Lists[$LibraryName] #Loop SPListItem. If SPFolder, skip the item foreach ($ListItem in $List.Items){ #Set SavePath $SaveFolder = $SavePath + "\" + $ListItem.ID #Check if SavePath exists already. If not, create SavePath if (!(Test-Path -path $SaveFolder)){ New-Item $SaveFolder -type directory } #Get all SPAttachment $AttachmentsColl = $ListItem.Attachments #Loop all SPAttachment foreach ($Attachment in $AttachmentsColl){ #Get attachment $file = $web.GetFile($listItem.Attachments.UrlPrefix + $Attachment) $bytes = $file.OpenBinary() #Save attachment $FilePath = $SaveFolder + " \" + $Attachment $fs = new-object System.IO.FileStream($FilePath, "OpenOrCreate") $fs.Write($bytes, 0 , $bytes.Length) $fs.Close() } } 復制代碼 WHY PowerShell 對于業務并不復雜但是要求代碼效率的操作,我們都傾向于使用SharePoint PowerShell 來進行操作,尤其是對于文檔備份這樣更像是IT運維的操作,我們更加推薦命令行。 這樣的操作有什么優點呢? 1. 操作簡單明了,不需要進行太多的代碼開發,沒有復雜的業務; 2. 我們保存下來,可以多次使用,比如這個備份,非常的靈活,修改也不需要重新編譯; 3. 類似CMD命令的方式,更容易讓IT人員和非SharePoint 開發接受。
Sharepoint 可以幫助企業用戶輕松完成日常工作。
|