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就格外 ...
随机推荐
- 保存html代码
function svcode(F) { if (document.all) { var F = $id(F); var E = window.open("", "_bl ...
- 微软BI 之SSAS 系列 - 实现Cube 以及角色扮演维度,度量值格式化和计算成员的创建
在熟悉完下面这三种维度的创建方式之后,就可以开始创建我们的第一个 Cube 了. SSAS 系列 - 自定义的日期维度设计 SSAS 系列 - 基于雪花模型的维度设计 SSAS系列 - 关于父子维度的 ...
- Linux中查看系统版本的方法
一.Linux系统中,XShell连接进去之后,查看系统版本的方法如下: 1.查找release文件 find /etc/ -name *-release 例如: 或者 2.查看release文件 c ...
- 通过HttpClient4.5模拟Form表单文件上传
public static void main(String[] args) { CloseableHttpClient httpclient = HttpClients.createDefault( ...
- achartengine(Google给android提供的画图工具包)的介绍和使用
AChartEngine(ACE)是Google为Android提供的一个开源绘制工具包.它集成了绘制多种图形的功能:折线图.散点图.气泡图.柱状图.饼图.仪表图等图形. 下载地址:http://do ...
- Mongostat 2.6详解
Mongostat C:\Users\John>Mongostat connected to: 127.0.0.1 insert query update delete getmore comm ...
- Android Things专题 1.前世今生
文| 谷歌开发人员技术专家, 物联网方向 (IOT GDE) 王玉成(York Wang) 2016 年 12 月,Google 公布了 Developer Preview 版的 Android Th ...
- Java JDBC编程套路教程
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/5847020.html 学习Java开发,一个必须掌握的知识点,就是数据库操作.当程序需要用到的数据达到一定程 ...
- Android玩转百度地图Sha1获取正确姿势?
场景一 由于近期项目钟要用到定位功能因此肯定须要用到地图以及地位功能,相信大家也知道眼下国内比較出名的地图像百度.高德.腾讯等这些还是用到比較多的.于是思考了一下决定还是用百度,相信老司机们都知道的哈 ...
- Axure 实现批量的勾选和反选
百度网盘:http://pan.baidu.com/s/1gf4RR2b 1.如何实现批量的勾选和反选的操作? 2.步骤 1)创建3个复选框.2个按钮(全选/反选) 2)设置全选按钮点击事件——选中“ ...