foam_sync.ps1 (LIFEBALANCE) 2025-06-19T01:06:29Z

This commit is contained in:
Ben Miller
2025-06-19 01:06:29 -06:00
parent eb8b59ee9f
commit 1439b682d6
2 changed files with 235 additions and 212 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# .gitignore
.logs/

View File

@ -35,16 +35,33 @@
$frequencyMinutes = 2 # How often the Scheduled Task should attempt to run this script $frequencyMinutes = 2 # How often the Scheduled Task should attempt to run this script
$executionTimeLimitBufferSeconds = 30 # Buffer: task stops if it runs longer than (frequency - buffer) $executionTimeLimitBufferSeconds = 30 # Buffer: task stops if it runs longer than (frequency - buffer)
# --- Scheduled Task Setup ---
$taskName = "FoamGitSync"
# --- Log File Setup ---
# Log inside the repository, in a .logs subfolder. Ensure this is in .gitignore
$scriptDirForLog = $PSScriptRoot # Use PSScriptRoot for robustness in determining script's dir
$logDir = Join-Path -Path $scriptDirForLog -ChildPath ".logs"
if (-not (Test-Path -Path $logDir)) {
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
}
$logFilePath = Join-Path -Path $logDir -ChildPath "foam_sync.log"
Start-Transcript -Path $logFilePath -Append -IncludeInvocationHeader -Force
try {
# Wrap main script logic in try for Stop-Transcript in finally
# --- Script Setup --- # --- Script Setup ---
$scriptPath = $MyInvocation.MyCommand.Path $scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path -Path $scriptPath -Parent $scriptDir = Split-Path -Path $scriptPath -Parent # This is the Git repository root
$scriptName = (Get-Item $scriptPath).Name $scriptName = (Get-Item $scriptPath).Name
Write-Host "Script: $scriptName at $scriptPath" Write-Host "Script: $scriptName at $scriptPath"
Write-Host "Repository directory: $scriptDir" Write-Host "Repository directory: $scriptDir"
Write-Host "Sync frequency: Every $frequencyMinutes minutes" Write-Host "Sync frequency: Every $frequencyMinutes minutes"
Write-Host "Log file: $logFilePath"
# --- Scheduled Task Setup ---
$taskName = "FoamGitSync"
$taskDescription = "Periodically synchronizes the Git repository at $scriptDir using $scriptName." $taskDescription = "Periodically synchronizes the Git repository at $scriptDir using $scriptName."
# Run as the user who executes this script. # Run as the user who executes this script.
@ -291,3 +308,7 @@ else {
Write-Host "Synchronization process completed successfully." Write-Host "Synchronization process completed successfully."
exit 0 exit 0
}
finally {
Stop-Transcript
}