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就格外 ...
随机推荐
- asp.net对象合并
public class com { /// <summary> /// 把参数转为JSON字符串 /// </summary> /// <param name=&quo ...
- MACD底背离选股公式——通达信、同花顺
{底背离,通达信版.同花顺版} DIFF:=EMA(CLOSE,) - EMA(CLOSE,); DEA:=EMA(DIFF,); MACD:=*(DIFF-DEA); QZQ:=BARSLAST(R ...
- Vue为什么没有templateUrl
Why Vue.js doesn't support templateURL Vue.js为什么不支持templateUrl模式 原因 templateUrl使用ajax的方式在运行时加载templa ...
- 神器phpstorm功能具体解释
phpstorm包括了webstorm的所有功能,更可以支持php代码. PhpStorm是一个轻量级且便捷的PHP IDE,其旨在提供用户效率,可深刻理解用户的编码,提供智能代码补全,高速导航以及即 ...
- Bash shell 命令行 快捷键
http://linuxtoy.org/archives/bash-shortcuts.html 生活在 Bash shell 中,熟记以下快捷键,将极大的提高你的命令行操作效率. 编辑命令 Ctrl ...
- SpringMVC对日期类型的转换@ResponseBody返回的DateTime是long类型
目前,多数web开发这都在使用Spring的框架.但是这个框架有个 @ResponseBody 注解返回json时,日期格式默认显示为时间戳. 而我们页面展示的时候一般都是以下格式: yyyy-MM- ...
- js Object.create 初探
1.作用 Object.create()方法创建一个新对象,使用现有的对象来提供新创建的对象的__proto__. https://developer.mozilla.org/zh-CN/docs/W ...
- CS 寄存器 和 IP 寄存器
下面将要介绍的是一组非常非常重要的寄存器,即 CS:IP . CS:IP 两个寄存器指示了 CPU 当前将要读取的指令的地址,其中 CS 为代码段寄存器,而 IP 为指令指针寄存器 . 什么叫做 ...
- Android开发之将拍摄的图片传至服务器
package com.example.oldtab; import java.io.ByteArrayOutputStream; import java.io.File; import java.i ...
- Axure 验证码、进度条、分页条(翻页)、搜索框、选项卡
百度网盘:http://pan.baidu.com/s/1jHP4qsm