ShareFile PowerShell and Windows Task Scheduler for local backup

  • 1
  • Problem
  • Updated 2 months ago
We are trying to accomplish backing up our entire ShareFile structure locally to a NAS. I have this currently setup and running. Only problem is, the task seems to be sporadic on how long it runs. Physically looking over the folder structure and files, I'm seeing that it's not finishing the sync before "Task Completed" as the Task Scheduler History shows. Sometimes it'll run just for a few minutes, other times it'll run for over 24 hours.

From what I can tell, everything is configured correctly, and I've also tested small syncs with success. The task is being ran with a domain account and proper permissions to the NAS for that account. The ShareFile account used is a Super User. Just for further information, this structure is over 2TB.

The Script

Add-PSSnapIn ShareFile
$sfLogin = Get-SfClient -Name "C:\ShareFileBackup\sflogin.sfps"
New-PSDrive -Name SFBackup -PSProvider ShareFile -Root "/" -Client $sfLogin
Sync-SfItem -ShareFilePath "/" -Synchronize -Download -LocalPath "\\wattnas\ShareFile" -Recursive -Strict

The Scheduled Task







Regards,
Barrett

Photo of Barrett Cowan

Barrett Cowan

  • 2 Posts
  • 0 Reply Likes

Posted 11 months ago

  • 1
Photo of Barrett Cowan

Barrett Cowan

  • 2 Posts
  • 0 Reply Likes
Still seeing the same behavior here. Anyone have any input? I have a feeling this may be an issue with the size of the entire structure and the -Strict option possibly. Is there anyway to log, I'm not seeing any options for it?
Photo of Peter Oven

Peter Oven

  • 18 Posts
  • 3 Reply Likes
With 2 TB I am not surprised that it's not completing the sync. I have 500 GB or so and I had to break the sync into sections, so that a failure of one part does not cause the whole thing to fail. I just run this every week using a scheduled task.


# Sharefile Backup Script
# Peter Oven
# 20180404 V1.0
# 20190717 V2.0
# 20190724 V2.1
#
# developed using Powershell SDK v1.92
# Based on code found at the following web pages
# https://github.com/citrix/ShareFile-PowerShell/releases
# https://support.citrix.com/article/CTX207460
# https://www.citrix.com/blogs/2014/05/16/getting-started-with-the-powershell-sdk/
# https://www.citrix.com/blogs/2014/11/13/transitioning-from-sfcli-to-sharefile-powershell/
# https://www.vexasoft.com/blogs/powershell/7255220-powershell-tutorial-try-catch-finally-and-error-handling-in-powershell

# Directories to Back Up
$sharedFoldersLocations = "External","WES Energy and Environment"
$wesLocations = "Individual Storage","WES Business","USDA","Reference Materials","Projects","AutoCAD Resources","BoilerMACT Compliance","Miscellaneous","Contracts","Proposals","Project Cost Estimating","USDA Technical Support"

# for manual adjustments to limit the backup extent
#$sharedFoldersLocations = $null
#$wesLocations = "BoilerMACT Compliance"

# logging system https://stackoverflow.com/questions/7834656/create-log-file-in-powershell
$logfile = "C:\SF\logs\sf-Backup.log"
Function Write-Log {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$False)]
[ValidateSet("INFO","WARN","ERROR","FATAL","DEBUG")]
[String]
$Level = "INFO",
[Parameter(Mandatory=$True)]
[string]
$Message,
[Parameter(Mandatory=$False)]
[string]
$logfile
)
$Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
$Line = "$Stamp $Level $Message"
If($logfile) {
Add-Content $logfile -Value $Line
}
Else {
Write-Output $Line
}
}

Function doSync {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]
$loc,
[Parameter(Mandatory=$True)]
[string]
$pathPrepend,
[Parameter(Mandatory=$True)]
[string]
$logfile
)
Add-PSSnapin ShareFile
# load login token
$sfc = Get-SfClient –Name "c:\SF\sflogin-poven.sfps"
# set up temporary sharefile drive
New-PSDrive -Name sfdrive -PSProvider ShareFile -Root "/" -Client $sfc
Write-Log "INFO" ("Starting "+$loc) $logfile
Try {
# Strict will delete locally any files which have been deleted on the sharefile account
#Sync-SfItem -ShareFilePath ("/Shared Folders"+$pathPrepend+$loc+"/") -Synchronize -Download -LocalPath ("c:\SF\Shared Folders"+$pathPrepend) -Recursive -Strict -ErrorAction Stop
Sync-SfItem -ShareFilePath ("/Shared Folders"+$pathPrepend+$loc+"/") -Synchronize -Download -LocalPath ("c:\SF\Shared Folders"+$pathPrepend) -Recursive -ErrorAction Stop
Write-Log "INFO" ("Backup of "+$loc+" complete") $logfile
}
Catch {
Write-Log "ERROR" ("Backup of "+$loc+" failed") $logfile
Write-Log "ERROR" $_.Exception.Message $logfile
}
Finally {
Remove-PSDrive sfdrive
Remove-PSSnapin ShareFile
}
}

foreach($location in $sharedFoldersLocations)
{
doSync $location "/" $logfile
}

foreach($location in $wesLocations)
{
doSync $location "/WES/" $logfile
}