Using the Windows Scheduler to run a SharePoint PowerShell Backup Script

Problem

SharePoint administrators need to run regular backups using PowerShell, the STSADM tool or in Central Administration. There is no "built in" way to automate these backups. Wouldn‘t it be great to devise a method to automated these jobs?

Solution

The solution is just to create a batch file that can execute a PowerShell script, and then launch it from the Windows Task Scheduler.


PowerShell Command to Backup SharePoint Site Collection

backup-spsite -identity http://SPFarm:20045/ -path C:\Backup\Backup.bak

OR

backup-spsite -identity http://SPFarm:20045/ -path C:\Backup\Backup.bak –force
//Note: use force to overwrite existing file

So, you can use the backup-spsite command to do site backup (the example shows http://SPFarm:20045/). The following script will start a full backup to C:\backup where you can send a site collection URL and backup file name as a parameter to the PowerShell Script.

$args[0] = http://SPFarm:20045/ [Source site location URL]
$args[1] = C:\backup\backup_site.bak [Destination path]

Step 1: Create Windows PowerShell script

Add-PSSnapin Microsoft.SharePoint.PowerShell
backup-spsite -identity $args[0] -path $args[1] -force

(You could) save it as C:\Scripts\BackupSPSite.ps1 - - (Windows PowerShell script files are .ps1 files.) Now you have to call this script from batch file.

Step 2: Create Batch Script to execute PowerShell script

@echo off
SET SOURCE_SITE=http://SPFarm:20045/
SET DEST=C:\backup\Backup_site.bak
echo "backup Started at" %DATE% >> C:\ backup\Log.txt
powershell -command C:\Scripts\BackupSPSite.ps1  %SOURCE_SITE% %DEST%
echo "Backup completed successfully at %DEST%" on %DATE% >> C:\ backup\Log.txt
@echo on

Save it as C:\Scripts\BackupSPSite.bat. Now you have to run this script.

Step 3: Run Batch Script to execute PowerShell script

So now you can automate your daily backup of a SharePoint Site. You can also run an entire Farm backup just by using the following command in a PowerShell Script (i.e. C:\Scripts\BackupSPSite.ps1)

Backup-SPFarm -Directory C:\Backup -BackupMethod full

Next Steps

  • Download the complete script from here.
  • Modify the script for your source site and backup location.
  • Return to MSSharepointTips to read about other topics and ideas.
  • Check out MSSQLTips.com for great information about Microsoft SQL Server

Refer:http://www.mssharepointtips.com/tip.asp?id=1100.

Using the Windows Scheduler to run a SharePoint PowerShell Backup Script

时间: 2024-08-29 21:54:13

Using the Windows Scheduler to run a SharePoint PowerShell Backup Script的相关文章

Windows 商店应用中使用 SharePoint REST API

前面一篇我们介绍了 Office 365 REST API 的官方工具的使用,本篇我们来看一下 SharePoint REST API 本身的描述.结构和使用方法,以及一些使用经验. 首先来看看SharePoint REST API 的概述: REST API 服务是在 SharePoint 2013 中被引入的,官方认为 REST API 服务可以媲美于现有的 SharePoint 客户端对象模型.开发人员可以使用任何支持 REST Web 请求的技术(C#,javascript,java,o

SharePoint PowerShell部署开发好的WebPart到服务器上

内容仅供参考,需结合实际需求来处理. =========SharePoint 环境下运行ps1文件,ps1内容如下======= 1 Set-ExecutionPolicy ByPass 2 Add-PSSnapin Microsoft.SharePoint.PowerShell 3 4 Add-SPSolution -LiteralPath "C:\Deploy_2013-08-21_v2.2\WSP\Custom_Lib.wsp" 5 Add-SPSolution -Literal

在Windows Server 2008 R2上安装 PowerShell 5.0

在Windows Server 2008 R2上安装 PowerShell 5.0 安装.NET Framework 4.6.2 下载NDP462-KB3151800-x86-x64-AllOS-ENU.exe,安装 安装PowerShell 4.0(5.0依赖4.0) 下载Windows6.1-KB2819745-x64-MultiPkg.msu,安装. 安装PowerShell5.0 下载Win7AndW2K8R2-KB3134760-x64.msu,安装. 完成后,重启服务器.

sharepoint powershell 根据报错的GUID查询错误

打开sharepoint powershell Get-splogevent | ?{$_.Correlation -eq "GUID"}  | select Area,category,Level,EventID,Message | Format-List > c:\errlog.txt 把GUID替换成爆出错误的GUID

sharepoint 2013 使用SharePoint powershell 2013更改搜索服务器方法

$hostA = Get-SPEnterpriseSearchServiceInstance -Identity "DevSearch2013" Start-SPEnterpriseSearchServiceInstance -Identity $hostA Get-SPEnterpriseSearchServiceInstance -Identity $hostA $ssa = Get-SPEnterpriseSearchServiceApplication $newTopology

在Powershell ISE中添加sharepoint的智能提示,Enable SharePoint PowerShell Commandlets in the PowerShell ISE

Powershell ISE在默认状态下有一个不好的地方就是不会显示关于SharePoint的一些智能提示,例如你写一个"get-"后面提示的选项里没有sp开头的一些对象.于是找了一下解决方案. 首先打开Powershell ISE, 把下面的代码拷贝到ISE中 1 if (!(test-path $profile )) 2 { 3 new-item -type file -path $profile -force 4 } 5 6 7 $cmd = 'if((Get-PSSnapin

Windows Server 2012 R2 WSUS-14:powershell管理WSUS

最近发现MDT推出去的系统的有不同问题,其问题就不说了,主要是策略权限被域继承了.比如我们手动安装的很多东东都是未配置壮态,推的就默认为安全壮态了,今天细找了一下,原来把这个关了就可以了. Windows Server 2012 R2 WSUS-14:powershell管理WSUS

sharepoint powershell 批量处理匿名访问

配置Web Application启用匿名访问 Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $webApp = Get-SPWebApplication 'http://sharepoint.crescent.com/' $webApp.IisSettings['Default'].AllowAnonymous=$true $webApp.update() 配置单个网站启用匿名访

Windows之文件夹中打开PowerShell

Windows之文件夹中打开PowerShell 为了解决Windows中在某个路径下使用PowerShell,而不是使用传统的cd命令切换过去,具体做法如下: 打开文件夹 在文件夹的内容区按下Shift+右击 点击在此处打开PowerShell即可. 结果: 原文地址:https://www.cnblogs.com/ZN-225/p/10269504.html