-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_main_script.ps1
98 lines (76 loc) · 2.52 KB
/
_main_script.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
<#
.Synopsis
Automated script to run restic backup, forget, check.
.DESCRIPTION
See the README
Parameters:
- $BackupConfigPath: folder that contains config files, like "/path/to/config".
This folder must contain:
- common.ps1
- common_windows.ps1 and common_unix.ps1
- config_SPECIFIC.ps1
- $BackupConfigName: config_SPECIFIC.ps1 file for the specific backup, like "config_template.ps1"
It also relies on all the scripts in the current script folder.
.EXAMPLE
./_main_script.ps1 "/home/restic/config" "config_template.ps1"
#>
# ----------------------
# PARAMETERS
# ----------------------
[CmdletBinding()]
param(
[Parameter(Position=0, mandatory=$true)]
[String]$BackupConfigPath,
[Parameter(Position=1, mandatory=$true)]
[String]$BackupConfigName
)
# ----------------------
# DEPENDENCIES LOADING
# ----------------------
# Configuration
$InitializeEnvironmentScript = Join-Path $PSScriptRoot "environment_initialize.ps1"
. $InitializeEnvironmentScript # No need to pass variable as we are on the same scope
# Functions
$FunctionsScript = Join-Path $PSScriptRoot "functions_windows.ps1"
. $FunctionsScript
# Logging
$InitializeLogsScript = Join-Path $PSScriptRoot "log_initialize.ps1"
. $InitializeLogsScript
# ----------------------
# CHECKS PRIOR STARTING BACKUP
# ----------------------
# Load OS common config
if ([environment]::OSVersion.Platform -eq "Win32NT") {
# Check if current session is elevated
If (-not (Get-IsCurrentSessionElevated) ) {
Write-Warning "Current session isn't elevated, error could happens."
}
# Check if current connection is metered
If (Get-IsCurrentNetworkMetered) {
Write-Warning "Current network is metered, exiting."
exit
}
}
# ----------------------
# UPDATE RESTIC AND RCLONE
# ----------------------
if ($AutoUpdateApps) {
$BackupScript = Join-Path $PSScriptRoot "function_update.ps1"
. $BackupScript
} else {Write-Output "`nSkip auto-update`n"}
# ----------------------
# RESTIC BACKUP
# ----------------------
$BackupScript = Join-Path $PSScriptRoot "restic_backup.ps1"
. $BackupScript
# ----------------------
# RESTIC FORGET, CHECK AND CLEAN LOG
# ----------------------
$BackupScript = Join-Path $PSScriptRoot "restic_forget.ps1"
. $BackupScript
$BackupScript = Join-Path $PSScriptRoot "restic_check.ps1"
. $BackupScript
$BackupScript = Join-Path $PSScriptRoot "log_directory_cleanup.ps1"
. $BackupScript
# $BackupScript = Join-Path $PSScriptRoot "restic_stats.ps1"
# . $BackupScript