-
Notifications
You must be signed in to change notification settings - Fork 0
/
0_Robocopy INTENSO LW X Unraid.ps1
107 lines (91 loc) · 3.58 KB
/
0_Robocopy INTENSO LW X Unraid.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
<#
.SYNOPSIS
Backup Tool for Robocopy by Fother Mucker
.NOTES
Last Update: 30.05.2024
#>
#region staticVariables
[string]$source = "\\10.10.0.10\share"
[string]$dest = "X:\_Unraid"
[int]$multiThread = 3 # MultiThread
[string]$logFolder = $dest.Split("_")[0] + "_Logs"
[string]$gitReposLocation = "D:\_Repo" # Backup Location
[array]$excludeDirectories = @(
$source + "\_CCTV"
)
#endregion
#region functions
function Get-Logtime {
$Timeformat = "yyyy-MM-dd HH:mm:ss"
return $(Get-Date -Format $Timeformat)
}
#endregion
Clear-Host
Write-Output "`n ______ _"
Write-Output " | ___ \ | | "
Write-Output " | |_/ / __._ ___| | ___ _ _ __ "
Write-Output " | ___ \/ _` |/ __| |/ / | | | '_ \ "
Write-Output " | |_/ / (_| | (__| <| |_| | |_) |"
Write-Output " \____/ \__,_|\___|_|\_\\__,_| .__/ "
Write-Output " | | "
Write-Output "VeraCrypt Backuptool 2021-2024 |_| pwsh v$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Patch)"
Write-Output " Running on Host: '$((hostname).ToUpper())'`n"
# Start Procere
[string]$Question = Read-Host "[$(Get-Logtime)] [INFO] Drive already mounted with Letter 'X' (y/n)?"
if ($Question -notlike "y") {
Write-Output "[$(Get-Logtime)] Bye!"
Exit
}
# Asking for Shutdown
[string]$shutdown = Read-Host "[$(Get-Logtime)] [INFO] Shutdown after finishing? (y/n)?"
if ($shutdown -notlike "y" -or $shutdown -notlike "n") {
Write-Output "[$(Get-Logtime)] [INFO] Wrong Answer! Ignoring Shutdown!"
}
# Check for Logfile Folder
if (!(Test-Path -Path $logFolder)) {
try {
Write-Output "[$(Get-Logtime)] [INFO] Folder for Logfiles missing! Creating Folder '$logFolder' now ..."
$null = New-Item -Path $logFolder -ItemType "directory"
}
catch {
throw "[ERROR] Can't create Folder '$logFolder': $($_.Exception.Message)!"
}
}
else {
Write-Output "[$(Get-Logtime)] [OK] Folder exist! Proceed ..."
}
# Checking for Backup Drive
$Drive = Get-WmiObject Win32_Volume -Filter ("DriveType={0}" -f [int][System.IO.DriveType]::Removable) | Where-Object { $_.Name -Like $dest.Split("_")[0] }
if (!$Drive) {
throw "[ERROR] Drive not found or is not mounted as removable Drive. Check your Settings and try again!"
}
else {
Write-Output "[$(Get-Logtime)] [OK] Drive '$($Drive.Label)' found with max. Capacity of '$([math]::round($Drive.Capacity /1TB,1)) TB'!"
}
Write-Output "[$(Get-Logtime)] [INFO] Starting Robocopy with '$multiThread' parallel Threads now ..."
Write-Warning "[$(Get-Logtime)] Ignoring Directories: '$($excludeDirectories -join ", ")'!" -WarningAction Continue
#region Unraid Backup
Robocopy.exe $source $dest /MIR /TEE /COPY:DAT /DCOPY:T /MT:$mt /XD $excludeDirectories /LOG+:"$logFolder\$(Get-Date -Format yyyy-MM-dd)`_Backup.log"
if ($?) {
Write-Output "[$(Get-Logtime)] [OK] Robocopy Backup finished successfully!"
}
#endregion
#region Create Backup from Git Repos
$allRepos = Get-ChildItem -Path $gitReposLocation
Write-Output "[$(Get-Logtime)] [INFO] Starting git Backup of '$(($allRepos).Count)' Repositories ..."
[int]$count = 1
$allRepos | ForEach-Object {
Write-Output "[$(Get-Logtime)] [$count/$(($allRepos).Count)] [INFO] Backing up '$($_.Name)' ..."
Set-Location $_.Fullname
git bundle create ("X:\_Repos\" + $(Get-Date -Format yyyy-MM-dd) + "_" + $($_.Name) + ".bundle") --all
$count++
}
#endregion
if ($?) {
Write-Output "`n[$(Get-Logtime)] [OK] All Backup Operations done. Exit here!"
}
if ($shutdown -like "y") {
Write-Output "[$(Get-Logtime)] Shutdown Computer now ..."
Stop-Computer -Force
}
#Exit