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就格外 ...
随机推荐
- VS2017安装或卸载错误1303
为添加一个Python开发环境,运行Visual Studio Installer安装报错,下面是日志: 问题日志 安装出现问题. 可通过以下方式排查包故障问题: 1. 使用以下搜索 URL 来搜索针 ...
- Java 生成ZIP文件
public static byte[] fileToZip(){ ZipOutputStream append = null; ByteArrayOutputStream bos = new Byt ...
- C#判断网站是否能访问或者宕机的方法
最近有位朋友说他有很多网址,可能有些已经过期或者不能访问了.自己去一个一个点可以,但又很麻烦! 再过一段时间又要去检查一次,每次都这样就不方便了! 于是就做了个小程序给帮他检测一下. 以下做了一个例子 ...
- SqlDataAdapter概述
SqlDataAdapter是 DataSet和 SQL Server之间的桥接器,用于检索和保存数据.SqlDataAdapter通过对数据源使用适当的Transact-SQL语句映射 Fill(它 ...
- 演示一下:rm -rf /
- 为wget命令设置代理
实验环境:ubuntu 12.04 LTS goagent 方法一.在环境变量中设置代理 export http_proxy=http://127.0.0.1:8087 方法二.使用配置文件 为wg ...
- cgroup 分析之CPU和内存部分
https://ggaaooppeenngg.github.io/zh-CN/2017/05/07/cgroups-%E5%88%86%E6%9E%90%E4%B9%8B%E5%86%85%E5%AD ...
- V-rep学习笔记:ROSInterface
Ubuntu 14.04 上安装V-rep 3.4.0 进入VREP官网下载Linux版本的V-rep(注意V-rep 3.4.0只有64位的版本,因此操作系统也要与之对应,Ubuntu 32位系统就 ...
- N皇后问题【递归求解】
n皇后问题:输入整数n, 要求n个国际象棋的皇后,摆在n*n的棋盘上,互相不能攻击,输出全部方案. 输入一个正整数N,则程序输出N皇后问题的全部摆法.输出结果里的每一行都代表一种摆法.行里的第i个数字 ...
- 1768:最大子矩阵(NOIP2014初赛最后一题)
1768:最大子矩阵 总时间限制: 1000ms 内存限制: 65536kB 描述 已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵. 比如 ...