-
Notifications
You must be signed in to change notification settings - Fork 1
/
environment_initialize.ps1
49 lines (40 loc) · 1.78 KB
/
environment_initialize.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
<#
.Synopsis
Initialize a restic environment for the main script
.DESCRIPTION
By using this script, the main script will have an environment ready for backup.
It will load, from the $BackupConfigPath folder received as parameter of the main script:
- common.ps1
- common_windows.ps1 or common_unix.ps1, depending on the running platform
- $BackupConfigName like config_template.ps1, received as parameter of the main script
#>
# ----------------------
# LOAD CONFIGS AND CHECKS PRIOR STARTING BACKUP
# ----------------------
# Load common config
$CommonConfigScript = Join-Path $BackupConfigPath "common.ps1"
. $CommonConfigScript
# Load OS common config
if ([environment]::OSVersion.Platform -eq "Win32NT") {
Write-Output "Current OS: Windows"
$CommonOSConfigScript = Join-Path $BackupConfigPath "common_windows.ps1"
} else {
Write-Output "Current OS: Unix"
$CommonOSConfigScript = Join-Path $BackupConfigPath "common_unix.ps1"
}
. $CommonOSConfigScript
# Load specific config
$BackupConfigScriptFullPath = Join-Path $BackupConfigPath $BackupConfigName
. $BackupConfigScriptFullPath
# ----------------------
# CONFIGURATION
# ----------------------
# Add Dry-Run if enabled, and add to backup log, otherwise remove the variable to avoid a ""
If ($ResticDryRun) {$ResticDryRun = "--dry-run"; "DRY-RUN ACTIVE"} else {Remove-Variable ResticDryRun}
# Add Use FS Snapshot if enabled, otherwise remove the variable to avoid ""
If ($ResticUseFSSnapshot) { $ResticUseFSSnapshot="--use-fs-snapshot"} else {Remove-Variable ResticUseFSSnapshot}
# Find restic and rclone executable, add to path as well
$ResticExecutable = Join-Path $ResticLocation "restic"
$RcloneExecutable = Join-Path $RcloneLocation "rclone"
$Env:PATH += ";" + $ResticLocation
$Env:PATH += ";" + $RcloneLocation