文档章节

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

 木宛城主
发布于 2015/03/02 19:43
字数 513
阅读 1
收藏 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
WSUS for windows 2012 安装及重装意外处理

WSUS 完整安装步骤网址,含PowerShell及GUI两种方式 https://www.rootusers.com/install-and-configure-windows-server-update-services-wsus/ WSUS 安装后默认服务端口是8530,如果需要改为...

zzimac
07/26
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Linux学习-1031(rsync同步工具 上)

10.28 rsync工具介绍 10.29/10.30 rsync常用选项 10.31 rsync通过ssh同步 一、 rsync工具介绍 rsync是一个同步工具,在日常的运维中常会用到。它可以本地同步,也实现可以远程两台机器同步。...

wxy丶
19分钟前
1
0
python实战一期:第一天

1. 为什么学习python 1.1 为什么要学Python? Python第一是个非常牛B的脚本语言,能满足绝大部分自动化运维的需求,又能做后端C/S架构,又能用WEB框架快速开发出高大上的Web界面,只有当你自...

laoba
21分钟前
2
0
Java并发编程学习三:线程同步的关键字以及理解

上篇文章中介绍了Java线程的带来的问题与内存模型中介绍了线程可能会引发的问题以及对应Java的内存模型,顺带介绍了Volatile和Sychronized关键字。今天对Java中涉及到的常见的关键类和关键字...

JerryLin123
28分钟前
0
0
我用代码来给你们分析一个赚钱的技巧

赚钱是个俗气的话题,但又是人人都绕不开的事情。我今天来“科学”地触碰下这个话题。 谈赚钱,就会谈到理财、投资,谈到炒股。有这样一个笑话: 问:如何成为百万富翁? 答:带一千万进入股...

crossin
28分钟前
1
0
spring MatchingBean应用

1、编写接口FactoryList import java.util.List;public interface FactoryList<E extends MatchingBean<K>, K> extends List<E> { E getBean(K factor); List<E> getBeanLi......

重城重楼
41分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部