zoukankan      html  css  js  c++  java
  • 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:BackupBackup.bak

    OR

    backup-spsite -identity http://SPFarm:20045/ -path C:BackupBackup.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:ackup 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:ackupackup_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:ScriptsBackupSPSite.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:ackupBackup_site.bak
    echo "backup Started at" %DATE% >> C: backupLog.txt
    powershell -command C:ScriptsBackupSPSite.ps1  %SOURCE_SITE% %DEST%
    echo "Backup completed successfully at %DEST%" on %DATE% >> C: backupLog.txt
    @echo on
    

    Save it as C:ScriptsBackupSPSite.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:ScriptsBackupSPSite.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.

  • 相关阅读:
    使用私有api实现自己的iphone桌面,并根据app的使用次数对app排序
    坐标系的属性
    带坐标轴的几何画板
    空间几何体的直观图matlab
    设置npm的registry
    (原创)机器学习之numpy库中常用的函数介绍(一)
    (原创)交叉编译 tesseract
    (原创)计算机视觉之数学原理-基础篇
    (原创)nRF51 DFU 初始化包介绍及生成工具
    (原创)使用nRF51822/nRF51422创建一个简单的BLE应用 ---入门实例手册(中文)之五
  • 原文地址:https://www.cnblogs.com/PeterHome/p/3924378.html
Copyright © 2011-2022 走看看