SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script
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

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

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

- 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

- 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 2010/SharePoint 2013 Custom Action: 基于Site Collection 滚动文字的通知.
应用场景: 有时候我们的站点需要在每个页面实现滚动文字的通知,怎么在不修改Master Page的情况下实现这个功能?我们可以使用Javascript 和 Custom Action 来实现. 创建一 ...
- backup site collection
http://stackoverflow.com/questions/5376380/sharepoint-2010-change-sitecollection-urlstsadm -o backup ...
- 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 ...
- 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 ...
- 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 ...
- [转]Installing SharePoint 2013 on Windows Server 2012 R2
转自:http://www.avivroth.com/2013/07/09/installing-sharepoint-2013-on-windows-server-2012-r2-preview/ ...
- SharePoint 2013备份方法整理
关于SharePoint备份 SharePoint的备份是一个数据副本,主要用于在系统出现故障后还原和恢复该数据. 备份的工具主要有以下几种(写的不全,欢迎补充.) SharePoint管理中心的备份 ...
- 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 ...
- SharePoint 2013功能(SPFeature)与GUID对照表
自从上次遇到了一些无法开启SharePoint功能的事件之后(详见<SharePoint 2013 托管导航无法被开启的解决办法>一文),对于在SharePoint中所提示的GUID就格外 ...
随机推荐
- Android 之 沉浸式状态栏及顶部状态栏背景色设置
现在很多应用都引用了沉浸式状态栏,如QQ,效果下图: 效果很酷炫,其实设置也很简单.但是,需要注意的是,这种效果只能在API19以及以上版本中才能够做到. 方法一: 首先,如果想让界面Activity ...
- Hbase master启动报错:Failed construction of Master: class org.apache.hadoop.hbase.master.HMaster Caused by: java.net.UnknownHostException:
Hbase master启动报错: java.lang.RuntimeException: Failed construction of Master: class org.apache.hadoop ...
- win7下安装matlab后打开出错“error starting desktop”的解决办法
在matlab快捷图标上右键,选择"还原以前的版本"--"兼容性"选项卡,在"以兼容模式运行这个程序"前面打勾,并选择"windo ...
- Endorsement 业务逻辑介绍
本文主要介绍保单系统中Endorsement功能的基本逻辑和过程,主要参考OIC系统 保单系统 保险公司用来管理保单的信息系统,这里简称为保单系统.主要作用是收集和维护投保人信息和投保信息,计算保费, ...
- MapReduce实现大矩阵乘法
来自:http://blog.csdn.net/xyilu/article/details/9066973 引言 何 为大矩阵?Excel.SPSS,甚至SAS处理不了或者处理起来非常困难,需要设计巧 ...
- gdb 小技巧
https://www.gitbook.com/book/wizardforcel/100-gdb-tips/details
- Python——XPath使用
一:XPath介绍 XPath全称XML路径语言,用于确定XML文档中某部分位置.XPath基于XML树状结构,在树中寻找结点. 现在,一般使用XPath在XML中查找.提取信息,同时,它也支持HTM ...
- 〖Android〗ant build android project, setting android.jar precedence
最近公司的一个项目中,新增了classes.jar包,与android.jar有冲突,必须得在加载android.jar前行加载classes.jar: 在持续集成环境中须使用ant编译,classe ...
- 7、java5线程池之单一线程池newSingleThreadExecutor
JDK文档说明: 创建一个使用单个 worker 线程的 Executor,以无界队列方式来运行该线程.(注意,如果因为在关闭前的执行期间出现失败而终止了此单个线程,那么如果需要,一个新线程将代替它执 ...
- java 属性封装
//封装性 //封装概念: //1.是面向对象思想的三大特征之一 //2.封装细节是隐藏的,仅对外提供访问接口 //3.封装分类: //属性封装 //方法封装 //类的封装 //组件的封装 //模块化 ...