Skip to content

Instantly share code, notes, and snippets.

@lquenti
Created September 28, 2023 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lquenti/7c645e3ff0e6a554f4b8f21ca912eb78 to your computer and use it in GitHub Desktop.
Save lquenti/7c645e3ff0e6a554f4b8f21ca912eb78 to your computer and use it in GitHub Desktop.
Exclude AppData from TSM tivoli backups using powershell
<#
A script to write an exclude file for all users AppData for TSM Tivoli.
Copyright Lars Quentin 2023, licsensed as CC0 (Public Domain)
#>
<#
Configuration Variables:
- BASE_PATH:
Where the user folders are.
- GLOBAL_REGEX_PATTERN:
The "Regular Expression" pattern that filters which user folders are relevant.
If all are relevant, you can use the RegEx "^.*?$".
- OUTPUT_FILE_PATH:
Where the generated tivoli file should be saved.
Note that you need to have write access in that parent folder.
#>
$BASE_PATH = "C:\Users\"
# This RegEx matches a string that contains exactly 5 lower- or uppercase letters.
# If numbers are also relevant: "^[a-zA-Z0-9]{5}"
$GLOBAL_REGEX_PATTERN = '^[a-zA-Z]{5}$'
# Match everything.
# $GLOBAL_REGEX_PATTERN = '^.*?$'
$OUTPUT_FILE_PATH = ".\EXCLUDE_LIST.txt"
<# end configuration, begin of program #>
function GetMatchedDirectories {
param (
[string]$BasePath,
[string]$RegexPattern
)
$matchedDirectories = Get-ChildItem -Path $BasePath |
Where-Object { $_.PSIsContainer -and $_.Name -match $RegexPattern } |
Where-Object { Test-Path (Join-Path $_.FullName "AppData") } |
ForEach-Object { $_.FullName }
return $matchedDirectories
}
function WriteStringToFile {
param (
[string]$MatchedDir
)
$stringToWrite = "exclude ${MatchedDir}\AppData"
Add-Content -Path $OUTPUT_FILE_PATH -Value $stringToWrite
}
function Main {
$matchedDirs = GetMatchedDirectories -BasePath $BASE_PATH -RegexPattern $GLOBAL_REGEX_PATTERN
foreach ($dir in $matchedDirs) {
Write-Host $dir
WriteStringToFile -MatchedDir $dir
}
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment