文档章节

SharePoint 2013 How to Backup Site Collection Automatically With a PowerShell Script

 木宛城主
发布于 2015/03/02 19:39
字数 513
阅读 2
收藏 0

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.

 

 

 

 

 

 

© 著作权归作者所有

共有 人打赏支持
粉丝 2
博文 222
码字总数 199010
作品 0
黄浦
【Powershell】早期操作系统如何更新安装Windows PowerShell 4.0

http://social.technet.microsoft.com/wiki/contents/articles/21016.how-to-install-windows-powershell-4-0.aspx Windows PowerShell 4.0 is part of the Windows Management Framework 4.......

xifalniang
2016/09/02
0
0
SharePoint Online和外网用户共享资源

豆子今天早上收到一个用户请求,要求他们部门的sharepoint site可以和外网用户共享资源。我的第一个反应应该很容易的吧,直接登录Office365的管理界面,然后在Sharepoint admin Center里面修...

beanxyz
07/03
0
0
PowerShell为什么强大

微软是一个很”低调”的公司,取名为微软,感觉有“微微软下去”的意思,这是个玩笑了。windows 操作系统 和office办公软件,如此之优秀,微软也没敢命名为PowerOS 和 PowerOffice,但是在Mon...

babylater
07/02
0
0
使用PowerShell关闭和锁定屏幕

ThinkPad T430没有关闭屏幕的功能键,不太方便,正好最近在折腾PowerShell,便写个脚本来实现这个功能。 1. 相关内容 1.1. PowerShell配置 为了更方便的使用脚本,需要用到3.0版的模块自动装...

joshuazhan
2014/01/04
0
0
Exchange 2019预览版部署安装——Part2

上一篇文章,大致分享了Exchange 2019的新功能和我测试Exchange 2019的大致环境介绍。下面具体分享安装过程。总体来说Exchange 2019在WIndows server core上安装比之前的版本安装简单很多,无...

jialt
07/29
0
0

没有更多内容

加载失败,请刷新页面

加载更多

记Structured Streaming 2.3.1的OOM排查过程

记Structured Streaming 2.3.1的OOM排查过程 缘起 最近在使用Structured Streaming开发一套自助配置SQL的来生成流式作业的平台,在测试的过程中发现有些作业长时间运行后会有Executor端的OOM...

纳兰清风
1分钟前
0
0
通过 websocket 连接 openfire

通过 websocket 连接 openfire 一、简介 老版本是需要安装websocket插件的。之前版本就不说了。 二、 引入XML与JSON互转的js <script src="lib/XML/ObjTree.js"></script><script src="lib......

lwenhao
4分钟前
0
0
MicropPython的学习,如何从0到1?

是Java还是C++ ? 是Go还是Python? 你为你最爱或者最熟悉的编程语言打Call了吗? Python在国外是一门非常热门的编程语言,近些年在国内也被发掘与追捧, Python的开放、简洁、黏合正符合了现发...

bodasisiter
6分钟前
0
0
Django框架17: Celery的使用

Celery介绍 1.什么是Celery Celery是一个python模块,它在官网的定义:Celery is asynchronous task queue/job based on distributed message passing. It is focused on real-time operatio......

代码打碟手
11分钟前
0
0
poi的excel解析工具类

import org.apache.commons.lang.StringUtils;import org.apache.commons.lang.time.DateFormatUtils;import org.apache.commons.lang.time.DateUtils;import org.apache.poi.hssf.use......

Sheav
15分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部