-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackupFile.ps1
38 lines (31 loc) · 1.09 KB
/
BackupFile.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
)
If(-Not (Test-Path $Path))
{
Throw "The source directory $Path does not exist, please specify an existing directory"
}
If ($PathIsWebApp -eq $True) {
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)"
}
}
$date = Get-Date -format "yyyy-MM-dd"
$DestinationFile = "$($DestinationPath + 'backup-' + $date + '.zip')"
If (-Not (Test-Path $DestinationFile))
{
Compress-Archive -Path $Path -CompressionLevel 'Fastest' -DestinationPath "$($DestinationPath + 'backup-' + $date)"
Write-Host "Created backup at $($DestinationPath + 'backup-' + $date + '.zip')"
} Else {
Write-Error "Today's backup already exists"
}