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时间类-格式-方法应用
一.当前日期+时间DateTime.Now c#/asp.net通过DateTime.Now这个类来获取当前的时间. DateTime dt = DateTime.Now; 2013/10/24 10 ...
- 牛客网-《剑指offer》-从尾到头打印链表
题目:http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035 C++ /** * struct ListNode { * i ...
- 牛客网-《剑指offer》-替换空格
题目:http://www.nowcoder.com/practice/4060ac7e3e404ad1a894ef3e17650423 C++ class Solution { public: vo ...
- 杂货&&心跳
https://github.com/jsfront/month/blob/master/2016/201605.md https://github.com/abdmob/x2js https://l ...
- 变址values(, %edi, 4)和间址4(%edi)
<汇编语言程序设计>Richard Blum著:5.2.4 在内存和寄存器之间传送数据 使用变址的内存位置: 可以在一个命令中指定把多个值存放到内存中: values: .in ...
- SHELL函数处理
SHELL函数调用分为两种: 第一种方式,有点像C语言调用函数的风格,直接把函数的执行结果复制给变量!不过,这个赋值过程和C语言的函数赋值是不一样的! C语言中,函数调用,是将函数的返回值返回给被调函 ...
- Java BIO、NIO、AIO 学习
正在学习<大型网站系统与JAVA中间件实践>,发现对BIO.NIO.AIO的概念很模糊,写一篇博客记录下来.先来说个银行取款的例子: 同步 : 自己亲自出马持银行卡到银行取钱(使用同步IO ...
- Definitaion of 'utsname' must be imported from module 'Darwin.POSIX.sys.utsname' before it is required
https://stackoverflow.com/questions/34430354/objective-c-gettimeofday-must-be-imported
- 修改mysql数据引擎的方法- 提高数据库性能
前言:同学告我说,他为了能使得数据查询变得快一点,修改的数据引擎,故查询一下,总结一下. 登录mysql后,查看当前数据库支持的引擎和默认的数据库引擎,使用下面命令: mysql>show en ...
- 转:3d max 2013 安装教程,凭着一种互联网精神提供给广大朋友
看到有人在ps区咨询如何安装3d max教程,当你进行第一步之前,请先断开网络连接第一步:运行安装程序 第二步:接受安装协议,点击下一步会提示输入序列号 第三步:你会看到已经安装完成了的界面 第四部: ...