-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backup.ps1
38 lines (38 loc) · 1.06 KB
/
Backup.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
Param (
[string]$Path = '.\app',
[string]$DestinationPath = '.\',
[switch]$PathIsWebApp
)
# check content if $PathIsWebApp
If ( $PathIsWebApp ) {
Try {
$ContainsApplicationFiles = `
"$( (Get-ChildItem $Path).Extension | Sort-Object -Unique )" `
-match '\.js|\.html|\.css'
If ( -Not $ContainsApplicationFiles ) {
Throw "Not a web app"
} Else {
Write-Host "Source files look good, continuing"
}
} Catch {
Throw "No backup created due to: $( $_.Exception.Message)"
}
}
# add check for $Path parameter
If ( -Not ( Test-Path $Path ) ) {
Throw "The source directory $Path does not exist, please specify an existing directory"
}
$date = Get-Date -format "yyyy-MM-dd"
$DestinationPath = `
$($DestinationPath + 'backup-' + $date + '.zip')
# add destination check
If ( -Not ( Test-Path $DestinationPath ) ) {
Compress-Archive `
-Path $Path `
-DestinationPath $DestinationPath `
-CompressionLevel Fastest
Write-Host `
"Created backup at $DestinationPath"
} Else {
Write-Error "Today's backup already exists"
}