SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

时间:2021-06-16 10:06:19

In this post I will introduce a way how to run a script for backing up SharePoint data which could be scheduled to run automatically.

Step 1:Create a PowerShell Script for Backing up a site collection

param([string] $site,[string] $dir,[string] $type)

if(!(Get-PSSnapin |Where-Object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}))

{

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

}

Start-SPAssignment -Global #防止内存泄露 #

function IsNullOrEmpty($str)

{

if($str)

{

return $false

}

else

{

return $true

}

}

$currentDate=Get-Date -Format "yyyy-MM-dd HH-mm-ss"

$logFile="$dir\BackupLog.log"

try

{

Write-Host "开始备份 $site ($type) 到 $dir"

Write "Site Collection Url:$site($type)">>$logFile

Write "Dir Path:$dir">>$logFile

if(IsNullOrEmpty($site))

{

Write-Host "Site Collection不能为空"

Write "Site Collection不能为空">>$logFile

return

}

if(IsNullOrEmpty($dir))

{

Write-Host "路径不能为空"

Write "路径不能为空">>$logFile

return

}

Backup-SPSite -Identity $site -Path $dir\$currentDate-$type.bak -Force

Write-Host "备份成功"

Write "成功于 $currentDate 备份 $site ">>$logFile

}

catch

{

Write-Host "备份失败,具体信息详见Log"

Write "$currentDate Error:$_">>$logFile

}

Stop-SPAssignment -Global

Write-Host "PowerShell 执行完毕"

Write "PowerShell 执行完毕">>$logFile

Basically,the above script will do the following:

  • Assign all the needed information to start backup.
  • Try to create a new backup script and name the file based on current date.
  • If Successful,it will write a success message to the log file.Otherwise,it will log the error/Exception

Step 2:Create a batch file to run the automatically backup powershell script

Notes,it will pass 3 parameters

cd /d %~dp0

powershell -file ".\autobackupSiteCollection.ps1" "http://sp/sites/UAT" "F:\SharePoint 2013 Backup" "UAT"

@pause

Step 3:Copy both the script and batch file to a folder on the SharePoint Server

Finally,Run the Batch File to start Backing up the site collection immediately.Or use Windows Task Scheduler to schedule it.

Step 4:Schedule a Batch File to Run automatically

There are occasions where you might need to schedule to run a batch file automatically in your windows server.So I will show you how to do it.

  • Click Start and under Search,type in "任务计划程序" and Open it
  • Select "创建基本任务" from "操作"Menu

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

  • Under "创建基本任务",type in Name you like and click Next

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

  • From the "触发器" Select,Select the option you like and click Next

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

  • I chose "每日" and Click Next,which brought me to this screen
  • Then click on "开始程序" and click next
  • Next Select "浏览" and Select the batch file you like run

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

  • Finally,Click on Finsh to create a Task

Now,that we have created a Task,we have to make sure it runs highest Privilege. we have to make sure that when you run the file it not should fail.

  • Right Click the task you just created and Select Property
  • Click on "使用最高权限运行" then click OK.

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script的更多相关文章

  1. SharePoint 2010/SharePoint 2013 Custom Action: 基于Site Collection 滚动文字的通知.

    应用场景: 有时候我们的站点需要在每个页面实现滚动文字的通知,怎么在不修改Master Page的情况下实现这个功能?我们可以使用Javascript 和 Custom Action 来实现. 创建一 ...

  2. backup site collection

    http://*.com/questions/5376380/sharepoint-2010-change-sitecollection-urlstsadm -o backup ...

  3. SharePoint - Another Way to Delete Site Collection

    I had created a site collection. But there is a problem of web-frontend server (I did not know when ...

  4. Fix SharePoint 2013 Site in Read only mode after an interrupted backup

    Problem When I was backing up SharePoint Site Collection Automatically with PowerShell and Windows T ...

  5. SharePoint 2013 Backup Farm Automatically With a Powershell and Windows Task Schedule

    In this post,I will show you SharePoint 2013 How to Backup Farm Automatically with a PowerShell and ...

  6. [转]Installing SharePoint 2013 on Windows Server 2012 R2

    转自:http://www.avivroth.com/2013/07/09/installing-sharepoint-2013-on-windows-server-2012-r2-preview/ ...

  7. SharePoint 2013备份方法整理

    关于SharePoint备份 SharePoint的备份是一个数据副本,主要用于在系统出现故障后还原和恢复该数据. 备份的工具主要有以下几种(写的不全,欢迎补充.) SharePoint管理中心的备份 ...

  8. Creating a Custom Page Layout in SharePoint 2013

    Creating a Custom Page Layout in SharePoint 2013 In my last article, I documented how to create a Ma ...

  9. SharePoint 2013功能(SPFeature)与GUID对照表

    自从上次遇到了一些无法开启SharePoint功能的事件之后(详见<SharePoint 2013 托管导航无法被开启的解决办法>一文),对于在SharePoint中所提示的GUID就格外 ...

随机推荐

  1. express之sendFile

    module.exports = function(req, res, opt) { var applyNo = req.query.applyNo; console.log("applyN ...

  2. F&num;之旅6 - 简单AV推荐系统

    上回说到用F#来写爬虫,这只是F#学习第一阶段的第一步.最开始,就对第一阶段做了这样的安排: 1.爬虫爬取AV数据 2.数据处理和挖掘 3.数据可视化(使用ECharts) 4.推荐系统 第一步很快就 ...

  3. &lpar; C&plus;&plus;&rpar; Access the hard drive&period;

    // Open up the volume HANDLE hVolume = CreateFile(wstrPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHA ...

  4. 查询和修改(Queries and Mutations)

    On this page, you'll learn in detail about how to query a GraphQL server. 在这个页面,你将会学习更多的关于如何查询GraphQ ...

  5. Maven - 解决Maven下载依赖包速度慢问题

    通常我们会因为下载jar包速度缓慢而苦恼,这十分影响开发效率,以及程序员的心情,在IDE下载jar时,无法对IDE做任何动作,只能大眼对小眼. 下载jar速度慢究其原因就是因为很多资源都是国外的,我们 ...

  6. IE兼容性问题解决方案4--form表单在IE下重复提交

    遇到过一种情况,点击提交按钮的时候,在IE下重复提交,而在其他浏览器下正常. 原因:button按钮不设置type时,在IE下被浏览器默认解析为type="submit",用js提 ...

  7. 什么是PMI

    项目管理协会 PMI PMI是世界领先的非盈利会员协会的项目管理专业机构 ,在全球185个国家有70多万会员和证书持有人.此外,PMI还是多个英文短语的缩写,较为著名的是采购经理指数PMI. 项目管理 ...

  8. kubernetes---docker-image

    imagePullPolicy  <String> Always : 总是从仓库下载 , 如果是image的tag是latest ,如果需要一直保持最新,则应设为Always ,从仓库下载 ...

  9. iOS - 切换rootViewController时&comma;销毁之前的控制器

    一.iOS在切换根控制器时,如何销毁之前的控制器?(切换rootViewController时注意的内存泄漏) 首先.在iOS的ARC机制下,任何对象,当没有其他对象对他进行强引用时,都会被自动释放. ...

  10. ActiveMQ P2P版的HelloWorld

    1.2 JMS应用程序接口 ConnectionFactory: 用户用来创建到JMS提供者的连接的被管对象.JMS客户通过可移植的接口访问连接,这样当下层的实现改变时,代码不需要进行修改. 管理员 ...