forked from Seidlm/PowerShell-Backup-Script
-
Notifications
You must be signed in to change notification settings - Fork 1
/
backup-script-dev.ps1
555 lines (493 loc) · 26.3 KB
/
backup-script-dev.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
########################################################
# Name: BackupScript.ps1
# Version: 2.5.0
# LastModified: 2021-04-19
# GitHub: https://github.com/vvildcard/PowerShell-Backup-Script
#
#
# Description:
# Copies one or more BackupDirs to the Destination.
# A Progress Bar shows the status of copied MB to the total MB.
# https://raw.githubusercontent.com/vvildcard/PowerShell-Backup-Script/master/README.md
#
#
# Usage:
# BackupScript.ps1 -BackupDirs "C:\path\to\backup", "C:\another\path\" -Destination "C:\path\to\put\the\backup"
# Change variables with parameters (ex: Add -NoStaging to turn off staging)
# Change LoggingLevel to 3 an get more output in Powershell Windows.
#
#
# Forked: 2020-08-01
# Forked by: [Ryan Dasso](https://github.com/vvildcard)
# Forked from: v1.5
# Creator: [Michael Seidl](https://github.com/Seidlm) aka [Techguy](http://www.techguy.at/)
# PowerShell Self-Service Web Portal at www.au2mator.com/PowerShell
#
# Feature Requests/Ideas
# Create txt file index of files in a zip backup.
# ZIP directly into the archive file.
### Variables
Param(
[string]$Versions = 2, # Default number of backups you want to keep.
# Source/Dest
[Parameter(Mandatory=$True)][string[]][Alias("b","s")]$BackupDirs, # Folders you want to backup. Comma-delimited.
# To hard-code the source paths, set the above line to: $BackupDirs = @("C:\path\to\backup", "C:\another\path\")
[Parameter(Mandatory=$True)][string][Alias("d")]$Destination, # Backup to this path. Can be a UNC path (\\server\share)
# To hard-code the destination, set the above line to: $Destination = "C:\path\to\put\the\backup"
[string[]]$DefaultExcludedDirs=@("$env:SystemDrive\Users\*\AppData\Local", "$env:SystemDrive\Users\*\AppData\LocalLow", "*\.git\*"), # This list of Directories will not be copied. Comma-delimited.
[string[]]$ExcludeDirs, # Second set of excluded directories for the user to define.
# Logging
[string]$TempDir = "$env:TEMP\BackupScript", # Temporary location for logging and zipping.
[string]$LogPath = "$TempDir\Logging",
[string]$LogFileName = "Log", # Name
[int]$LoggingLevel = 2, # LoggingLevel only for Output in Powershell Window, 1=smart, 3=Heavy
# Zip
[switch]$NoZip, # Don't Zip the backup.
[switch]$Use7ZIP, # Make sure 7-Zip is installed. (https://7-zip.org)
[string]$7zPath = "$env:ProgramFiles\7-Zip\7z.exe",
# Staging -- Ignored when $NoZip is specified. Staging moves all files to a temporary directory before zipping them
# for performance improvement, especially when copying over a slow link (it's faster to copy a single large zip file
# than many small files across the network or to a USB device). Staging keeps all the heavy lifting on the local
# disk, but can also use a lot of space. You need enough space to hold the temporary copy of the backed-up files and
# the ZIP of those files.
[switch]$NoStaging, # Sets $UseStaging. $Destination will be used for Staging.
[string]$StagingDir = "$TempDir\Staging", # Set your own location for staging.
[switch]$NoDeleteStaging, # Don't delete StagingDir after backup.
# Email
[switch]$SendEmail, # $True will send report via email (SMTP send)
[string]$EmailTo = 'test@domain.com', # List of recipients. For multiple users, use "User01 <user01@example.com>" ,"User02 <user02@example.com>"
[string]$EmailFrom = 'from@domain.com', # Sender/ReplyTo
[string]$EmailSMTP = 'smtp.domain.com' # SMTP server address
)
# Counters
$Items = 0
$Count = 0
$ErrorCount = 0
$BackupStartDate = Get-Date
### FUNCTIONS
# Logging
function Write-au2matorLog {
[CmdletBinding()]
param
(
[ValidateSet('DEBUG', 'INFO', 'WARNING', 'ERROR')][string]$Type,
[string]$Text
)
if ($Type -eq 'DEBUG') {
$TypeLevel = 3
} elseif ($Type -eq 'INFO') {
$TypeLevel = 2
} elseif ($Type -eq 'WARNING') {
$TypeLevel = 1
} else {
$TypeLevel = 0
}
# Set logging path
if (!(Test-Path -Path $logPath)) {
try {
$null = New-Item -Path $logPath -ItemType Directory
Write-Verbose ("Path: ""{0}"" was created." -f $logPath)
}
catch {
Write-Verbose ("Path: ""{0}"" couldn't be created." -f $logPath)
}
}
else {
Write-Verbose ("Path: ""{0}"" already exists." -f $logPath)
}
[string]$logFile = '{0}\{1}_{2}.log' -f $logPath, $(Get-Date -Format 'yyyyMMdd'), $LogFileName
$logEntry = '{0}: <{1}> <{2}> {3}' -f $(Get-Date -Format dd.MM.yyyy-HH:mm:ss), $Type, $PID, $Text
try { Add-Content -Path $logFile -Value $logEntry }
catch {
Start-sleep -Milliseconds 50
Add-Content -Path $logFile -Value $logEntry
}
if ($LoggingLevel -ge $TypeLevel) { Write-Host $Text }
}
# Backup Prep
# Set the staging directory and name the backup file or folder.
function BackupPrep () {
$script:BackupName = "Backup-$(Get-Date -format yyyy-MM-dd-hhmmss)"
if ($script:NoZip) { $script:Zip = $False } else { $script:Zip = $True; $script:ZipFileName = "$($script:BackupName).zip" }
Write-au2matorLog -Type DEBUG -Text "Zip = $($Zip)"
if ($script:NoStaging) { $script:UseStaging = $False } else { $script:UseStaging = $True }
Write-au2matorLog -Type DEBUG -Text "UseStaging = $($UseStaging)"
if ($script:NoDeleteStaging) { $script:ClearStaging = $False } else { $script:ClearStaging = $True }
Write-au2matorLog -Type DEBUG -Text "ClearStaging = $($ClearStaging)"
if ($script:UseStaging -and $script:Zip) {
$script:TempBackupDir = "$script:StagingDir"
} else {
$script:TempBackupDir = "$script:Destination\$script:BackupName"
}
Write-au2matorLog -Type DEBUG -Text "TempBackupDir = $($TempBackupDir)"
}
# Parse Excluded Directories into RegEx
function ExcludeCleanUp($Dirs) { # Clean-up and Convert each Directory to regex
foreach ($Entry in ($Dirs)) {
# Remove trailing backslashes and wildcards
while (($Entry.SubString($Entry.length-1) -eq ("*")) -or ($Entry.SubString($Entry.length-1) -eq ("\"))) {
$Entry = $Entry.Substring(0,$Entry.Length-1)
}
$Entry = $Entry.Replace("\", "\\") # Convert \ to \\ for regex
$Entry = $Entry.Replace(".","\.") # Convert . to \. for regex
$Entry = $Entry.Replace("*", ".*") # Convert wildcards for regex
$Entry += "\\.*" # Add trailing \\.*
$ExcludeString += $Entry + "|" # Add to the exclude list regex OR
}
$ExcludeString = $ExcludeString.Substring(0, $ExcludeString.Length - 1) # Remove the trailing |
Return [RegEx]$ExcludeString
}
# Create the TempBackupDir
Function NewBackupDir {
if (Test-Path $TempBackupDir) {
Write-au2matorLog -Type DEBUG -Text "Backup/Staging directory already exists: $TempBackupDir"
} else {
New-Item -Path $TempBackupDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
Write-au2matorLog -Type WARNING -Text "Created backup/staging directory: $TempBackupDir"
}
}
# Delete the oldest Directory backup
Function RemoveDirBackup {
# Count the previous directory backups and remove the oldest (if needed)
Write-au2matorLog -Type DEBUG -Text "Checking if there are more than $Versions backups in the Destination"
$BackupDirCount = (Get-ChildItem $Destination | Where-Object { $_.Attributes -eq "Directory" -and ($_.Name -like "Backup-????-??-??-??????") }).count
if ($BackupDirCount -gt $Versions) {
Write-au2matorLog -Type INFO -Text "Found $count Directory Backups"
$RemoveFolder = Get-ChildItem $Destination | Where-Object { ($_.Attributes -eq "Directory") -and ($_.Name -like "Backup-????-??-??-??????") } | Sort-Object -Property CreationTime -Descending:$False | Select-Object -First 1
if ($RemoveFolder) {
$RemoveFolder.FullName | Remove-Item -Recurse -Force
Write-au2matorLog -Type INFO -Text "Deleted oldest directory backup: $RemoveFolder"
}
} else {
Write-au2matorLog -Type DEBUG -Text "Not enough previous backups found. Skipping backup deletion."
}
}
# Delete the oldest Zip backup
Function RemoveZipBackup {
Write-au2matorLog -Type DEBUG -Text "Checking if there are more than $Versions Zip in the Destination"
$ZipBackupCount = (Get-ChildItem $Destination | Where-Object { $_.Attributes -eq "Archive" -and $_.Name -like "Backup-????-??-??-??????.zip" }).count
if ($ZipBackupCount -gt $Versions) {
Write-au2matorLog -Type INFO -Text "Found $ZipBackupCount Zip backups"
$RemoveZip = Get-ChildItem $Destination | Where-Object { $_.Attributes -eq "Archive" -and $_.Name -like "Backup-????-??-??-??????.zip" } | Sort-Object -Property CreationTime -Descending:$False | Select-Object -First 1
if ($RemoveZip) {
$RemoveZip.FullName | Remove-Item -Recurse -Force
Write-au2matorLog -Type INFO -Text "Deleted oldest zip backup: $RemoveZip"
}
} else {
Write-au2matorLog -Type DEBUG -Text "Not enough previous backup zips found. Skipping backup deletion."
}
}
# Check if TempBackupDir and Destination is available
function CheckDir {
Write-au2matorLog -Type WARNING -Text "Checking if Destination exists"
if (!(Test-Path $TempBackupDir)) {
Write-au2matorLog -Type ERROR -Text "$TempBackupDir does not exist"
return $False
}
if (!(Test-Path $Destination)) {
Write-au2matorLog -Type ERROR -Text "$Destination does not exist"
return $False
}
Write-au2matorLog -Type DEBUG -Text "Backup Dirs: $($TempBackupDir)"
Write-au2matorLog -Type DEBUG -Text "Destination: $($Destination)"
return $True
}
# Save all the Files
Function MakeBackup {
Write-au2matorLog -Type INFO -Text "Starting the Backup"
$BackupDirFiles = @{ } # Hash of BackupDir & Files
$Files = @()
$SumMB = 0
$SumItems = 0
$SumCount = 0
$colItems = 0
Write-au2matorLog -Type DEBUG -Text "Counting all files and calculating size"
# Count the number of files to backup.
foreach ($Backup in $BackupDirs) {
# Get recursive list of files for each Backup Dir once and save in $BackupDirFiles to use later.
# Optimize performance by getting included folders first, and then only recursing files for those.
# Use -LiteralPath option to work around known issue with PowerShell FileSystemProvider wildcards.
# See: https://github.com/PowerShell/PowerShell/issues/6733
write-host "Backup: $Backup"
if ($Backup) {
$Files = Get-ChildItem -LiteralPath $Backup -Recurse -Attributes !D+!ReparsePoint -ErrorVariable +errItems -ErrorAction SilentlyContinue | `
ForEach-Object -Process { `
Add-Member -InputObject $_ -NotePropertyName "ParentFullName" `
-NotePropertyValue ($_.FullName.Substring(0, $_.FullName.LastIndexOf("\" + $_.Name))) `
-PassThru -ErrorAction SilentlyContinue } | `
Where-Object { $_.FullName -notmatch $Exclude.ToString() } | ` # -and $_.ParentFullName -notmatch $Exclude } | `
Get-ChildItem -Attributes !D -ErrorVariable +errItems -ErrorAction SilentlyContinue | `
Where-Object { $_.DirectoryName -notmatch $Exclude.ToString() }
#$Files = $Files | Where-Object { $_.FullName -notmatch $Exclude.ToString() }
$BackupDirFiles.Add($Backup, $Files)
$colItems = ($Files | Measure-Object -property length -sum)
#write-host "colItems: $colItems"
#Write-au2matorLog -Type DEBUG -Text "DEBUG"
#Copy-Item -LiteralPath $Backup -Destination $BackupDir -Force -ErrorAction SilentlyContinue | Where-Object { $_.FullName -notmatch $exclude }
if ($colItems) {
$SumMB += $colItems.Sum.ToString()
$SumItems += $colItems.Count
}
}
}
# Calculate total size of the backup.
$TotalMB = "{0:N2}" -f ($SumMB / 1MB) + " MB"
Write-au2matorLog -Type INFO -Text "There are $SumItems files ($TotalMB) to copy"
# Log any errors from above from building the list of files to backup.
[System.Management.Automation.ErrorRecord]$errItem = $null
foreach ($errItem in $errItems) {
Write-au2matorLog -Type ERROR -Text "Skipping '$($errItem.TargetObject)' - Error: $($errItem.CategoryInfo)"
}
Remove-Variable errItem
Remove-Variable errItems
# Before copy files, remove the oldest previous backup (if needed)
RemoveDirBackup
# Copy files to the backup location.
Write-au2matorLog -Type WARNING -Text "Copying files to $TempBackupDir"
Write-au2matorLog -Type DEBUG -Text "BackupDirs = $($BackupDirs)"
foreach ($Backup in $BackupDirs) {
Write-au2matorLog -Type DEBUG -Text "Backup = $($Backup)"
$BackupAsObject = Get-Item $Backup # Convert the backup string path to an object to fix case sensitivity
# Write-au2matorLog -Type DEBUG -Text "BackupAsObject = $($BackupAsObject)"
$Files = $BackupDirFiles[$Backup]
# Write-au2matorLog -Type DEBUG -Text "Files = $($Files)"
foreach ($File in $Files) {
# Write-au2matorLog -Type DEBUG -Text "File.FullName = $($File.FullName)"
if ($BackupAsObject.Parent.FullName -like "?:\") { # This IF handles directories on the root of the tree
$RelativePath = $File.FullName.Replace("$($BackupAsObject.Parent.Name)", "")
# Write-au2matorLog -Type DEBUG -Text "BackupAsObject Parent = $($BackupAsObject.Parent.FullName)"
} else {
$RelativePath = $File.FullName.Replace("$($BackupAsObject.Parent.FullName)\", "")
# Write-au2matorLog -Type DEBUG -Text "BackupAsObject Parent = $($BackupAsObject.Parent.FullName)\"
} # RelativePath has the parent folder(s) and file name, starting from the directory being backed up.
# Example: "Desktop\myfile.txt"
# Write-au2matorLog -Type DEBUG -Text "RelativePath = $($RelativePath)"
try {
# Use New-Item to create the destination directory if it doesn't yet exist. Then copy the file.
Write-au2matorLog -Type DEBUG -Text "'$($File.FullName)' copied to '$TempBackupDir\$RelativePath'"
New-Item -Path (Split-Path -Path "$TempBackupDir\$RelativePath" -Parent) -ItemType "directory" -Force -ErrorAction SilentlyContinue | Out-Null
Copy-Item -LiteralPath $File.FullName -Destination "$TempBackupDir\$RelativePath" -Force -ErrorAction Continue | Out-Null
}
catch {
$ErrorCount++
Write-au2matorLog -Type ERROR -Text "'$($File.FullName)' returned an error and was not copied"
}
$Items += (Get-item -LiteralPath $File.FullName).Length
$status = "Copy file {0} of {1} and copied {3} MB of {4} MB: {2}" -f $count, $SumItems, $File.Name, ("{0:N2}" -f ($Items / 1MB)).ToString(), ("{0:N2}" -f ($SumMB / 1MB)).ToString()
$Index = [array]::IndexOf($BackupDirs, $Backup) + 1
$Text = "Copy data Location {0} of {1}" -f $Index , $BackupDirs.Count
Write-Progress -Activity $Text $status -PercentComplete ($Items / $SumMB * 100)
if ($File.Attributes -ne "Directory") { $count++ }
}
}
$SumCount += $Count
$SumTotalMB = "{0:N2}" -f ($Items / 1MB) + " MB"
Write-au2matorLog -Type DEBUG -Text "----------------------"
Write-au2matorLog -Type DEBUG -Text "Copied $SumCount files. Size of $SumTotalMB"
if ($ErrorCount) {
Write-au2matorLog -Type WARNING -Text "$ErrorCount files could not be copied"
}
# Send e-mail with reports as attachments
if ($SendEmail -eq $True) {
$EmailSubject = "$env:COMPUTERNAME - Backup on $(get-date -format yyyy.MM.dd)"
$EmailBody = "Backup Script $(get-date -format yyyy.MM.dd) (last Month).`n
Computer: $env:COMPUTERNAME`n
Source(s): $BackupDirs`n
Backup Location: $Destination"
Write-au2matorLog -Type INFO -Text "Sending e-mail to $EmailTo from $EmailFrom (SMTPServer = $EmailSMTP) "
# The attachment is $log
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubject -Body $EmailBody -SmtpServer $EmailSMTP -attachment $Log
}
}
# Zip Backup
Function ZipBackup {
$ZipStartDate = Get-Date
# Count the previous zip backups and remove the oldest (if needed)
RemoveZipBackup
Write-au2matorLog -Type INFO -Text "Compressing the Backup Destination"
if ($Use7ZIP) {
7ZipCompression -ZipPath "$TempBackupDir\*" -ZipDest "$TempBackupDir\$ZipFileName"
} else { # Use powershell-native compression
PowershellCompression -ZipPath "$TempBackupDir\*" -ZipDest "$TempBackupDir\$ZipFileName"
}
$ZipEnddate = Get-Date
$ZipSpan = $ZipEndDate - $ZipStartDate
$ZipDuration = "Zip duration $($ZipSpan.Hours) hours $($ZipSpan.Minutes) minutes $($ZipSpan.Seconds - $SleepTime) seconds"
Write-au2matorLog -Type INFO -Text "$ZipDuration"
# This would be a good place to put compression stats.
# $TotalMB
}
# 7-Zip Compression
Function 7ZipCompression {
param(
[string]$ZipPath,
[string]$ZipDest
)
Write-au2matorLog -Type DEBUG -Text "Use 7-Zip"
if (test-path $7zPath) {
Write-au2matorLog -Type DEBUG -Text "7-Zip found: $($7zPath)!"
set-alias sz "$7zPath"
#sz a -t7z "$directory\$zipfile" "$directory\$name"
} else {
Write-au2matorLog -Type DEBUG -Text "Looking for 7-Zip here: $($7zPath)"
Write-au2matorLog -Type ERROR -Text "7-Zip not found: Reverting to Powershell compression"
$Use7ZIP = $FALSE
}
if ($Use7ZIP -and $UseStaging) { # Zip to the staging directory, then move to the destination.
# Usage: sz a -t7z <archive.zip> <source1> <source2> <sourceX>
sz a -t7z $ZipDest $ZipPath
Write-au2matorLog -Type INFO -Text "Moving Zip to $Destination"
Move-Item -Path $ZipDest -Destination $Destination
} else { # Zip straight to the BackupDir.
sz a -t7z "$TempBackupDir\$ZipFileName" $TempBackupDir
}
}
# Powershell Compression
Function PowershellCompression {
param(
[string]$ZipPath,
[string]$ZipDest
)
Write-au2matorLog -Type DEBUG -Text "Using Powershell Compress-Archive"
#Write-au2matorLog -Type DEBUG -Text "TempBackupDir = $($TempBackupDir)"
#Write-au2matorLog -Type DEBUG -Text "StagingDir = $($StagingDir)"
#Write-au2matorLog -Type DEBUG -Text "ZipFileName = $($ZipFileName)"
#Write-au2matorLog -Type DEBUG -Text "Destination = $($Destination)"
$SleepTime = 2 # Seconds
Write-au2matorLog -Type DEBUG -Text "Pausing for $SleepTime seconds to let things settle"
Start-sleep -Seconds ($SleepTime)
Write-au2matorLog -Type DEBUG -Text "Starting compression"
Compress-Archive -Path $ZipPath -DestinationPath $ZipDest -CompressionLevel Optimal -Force
Write-au2matorLog -Type INFO -Text "Moving Zip to $Destination"
Move-Item -Path $ZipDest -Destination $Destination
}
### End of Functions
### Begin Main
Write-au2matorLog -Type INFO -Text "----------------------"
Write-au2matorLog -Type DEBUG -Text "Start the Script"
BackupPrep
# Create Backup Dir
NewBackupDir
# Parse Excluded Directories
$AllExcludedDirs = $DefaultExcludedDirs
if ($ExcludeDirs.length -gt 2) { # Add custom exclusions (if any were given)
$AllExcludedDirs += $ExcludeDirs }
Write-au2matorLog -Type WARNING -Text "Excluded Directories:" # List the excluded directories
foreach ($d in $AllExcludedDirs) {
Write-au2matorLog -Type WARNING -Text "`t$d" }
$Exclude = ExcludeCleanUp($AllExcludedDirs) # This is the final list of exceptions (in RegEx)
Write-au2matorLog -Type DEBUG -Text "Directory Exclusions (RegEx): $($Exclude.ToString())"
# Start the Backup
$CheckDir = CheckDir
if (-not $CheckDir) {
Write-au2matorLog -Type ERROR -Text "One of the Directories are not available, Script has stopped"
} else {
MakeBackup
$CopyEndDate = Get-Date
$CopySpan = $CopyEnddate - $BackupStartDate
Write-au2matorLog -Type INFO -Text "`nCopy duration $($CopySpan.Hours) hours $($CopySpan.Minutes) minutes $($CopySpan.Seconds) seconds"
Write-au2matorLog -Type INFO -Text "----------------------"
if ($Zip) {
ZipBackup
# Clean-up Staging
if ($ClearStaging) {
Write-au2matorLog -Type INFO -Text "Clearing Staging"
Get-ChildItem -Path $TempBackupDir -Recurse -Force | Remove-Item -Confirm:$False -Recurse -Force
}
# Clean-up TempBackupDir --- REMOVING: Combine this concept with the Staging concept.
Get-ChildItem -Path $TempBackupDir -Recurse -Force | Remove-Item -Confirm:$False -Recurse
Get-Item -Path $TempBackupDir | Remove-Item -Confirm:$False -Recurse
}
$TotalEndDate = Get-Date
$TotalSpan = $TotalEndDate - $BackupStartDate
$TotalDuration = "Total duration $($TotalSpan.Hours) hours $($TotalSpan.Minutes) minutes $($TotalSpan.Seconds) seconds"
Write-au2matorLog -Type INFO -Text "$TotalDuration"
}
### End Main
Write-au2matorLog -Type WARNING -Text "Backup $BackupName Finished"
#Write-Host "Press any key to close ..."
#$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
# SIG # Begin signature block
# MIIPVAYJKoZIhvcNAQcCoIIPRTCCD0ECAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUFZeYE8LG9MAlad1zNXIDOhOl
# tx6gggzFMIIFwDCCA6igAwIBAgITFgAAAAR84b1HddGLUAAAAAAABDANBgkqhkiG
# 9w0BAQsFADAdMRswGQYDVQQDExJFVFNNTU9NTlBLSU9SMDItQ0EwHhcNMTUwOTIz
# MTYxNTA1WhcNMzEwOTIxMjAzMDIzWjBJMRMwEQYKCZImiZPyLGQBGRYDY29tMRcw
# FQYKCZImiZPyLGQBGRYHamhhY29ycDEZMBcGA1UEAxMQRVRTTU1PUEtJQ0EwMi1D
# QTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALdVbFlHVe/fmyEbMyuT
# CdP0Q5SUwQEjvzy49EV+ld6Z2qCQkVdUErozBr/ZEEIGu9HzQAgQOHeJ1nTb23Hz
# v4Xt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