foam_sync.ps1 (LIFEBALANCE) 2025-06-19T01:06:29Z
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# .gitignore
|
||||
.logs/
|
||||
@ -35,16 +35,33 @@
|
||||
$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)
|
||||
|
||||
# --- 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 ---
|
||||
$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
|
||||
|
||||
Write-Host "Script: $scriptName at $scriptPath"
|
||||
Write-Host "Repository directory: $scriptDir"
|
||||
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."
|
||||
|
||||
# Run as the user who executes this script.
|
||||
@ -291,3 +308,7 @@ else {
|
||||
|
||||
Write-Host "Synchronization process completed successfully."
|
||||
exit 0
|
||||
}
|
||||
finally {
|
||||
Stop-Transcript
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user