-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwin-restic-ds.yaml
170 lines (159 loc) · 4.79 KB
/
win-restic-ds.yaml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
apiVersion: v1
kind: ConfigMap
metadata:
name: restic-ps-scripts
namespace: velero
data:
resticbackup.ps1: |-
# Restic Pwershell Backup Script
. c:\scripts\resticconfig.ps1
# Create log directory if it doesn't exit
if(-not (Test-Path $LogPath)) {
New-Item -ItemType Directory -Force -Path $LogPath | Out-Null
Write-Output "[[Init]] Repository successfully initialized."
}
# Create the local exclude file
if(-not (Test-Path $LocalExcludeFile)) {
New-Item -Type File -Path $LocalExcludeFile | Out-Null
}
# Initialize the restic repository
& $ResticExe --verbose init
if($?) {
Write-Output "[[Init]] Repository successfully initialized."
}
else {
Write-Warning "[[Init]] Repository initialization failed. Check errors and resolve."
}
# Run the backup
Write-Output "Starting Backup .."
& $ResticExe --verbose -q backup $hostbkppath $podbkppath --tag $tag --exclude-file=$WindowsExcludeFile --exclude-file=$LocalExcludeFile
if(-not $?) {
Write-Output "[[Backup]] Completed with errors"
$return_value = $false
}
Write-Output "Backup Completed .."
# Prune old backups
& $ResticExe forget -q --prune --keep-hourly 5 --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 5
& $ResticExe forget --keep-hourly 24 --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 7
resticrestore.ps1: |-
# Restic Pwershell Restore Script
. c:\scripts\resticconfig.ps1
resticschedule.ps1: |-
# Restic Pwershell Schedule Script
. c:\scripts\resticconfig.ps1
resticconfig.ps1: |-
# Custom variables
$DateStr = $(get-date -f dd-MM-yyyy-HHmm)
$server = $env:NODENAME
$pod = $env:POD_NAME
$namespace = $env:NAMESPACE
$podbkppath = $env:POD_BACKUP_DIR_PATH
$hostbkppath = "C:\aks"
$tag = $server
# Backup configuration variables
$ExeName = "restic.exe"
$InstallPath = "C:\restic"
$ResticExe = Join-Path $InstallPath $ExeName
$StateFile = Join-Path $InstallPath "state.xml"
$WindowsExcludeFile = Join-Path $InstallPath "windows.exclude"
$LocalExcludeFile = Join-Path $InstallPath "local.exclude"
$LogPath = Join-Path $InstallPath "logs"
$LogRetentionDays = 30
$InternetTestAttempts = 10
$GlobalRetryAttempts = 4
# Maintenance configuration variables
$SnapshotMaintenanceEnabled = $true
$SnapshotRetentionPolicy = @("--keep-daily", "30", "--keep-weekly", "52", "--keep-monthly", "24", "--keep-yearly", "10")
$SnapshotMaintenanceInterval = 7
$SnapshotMaintenanceDays = 30
$SnapshotDeepMaintenanceDays = 90
---
apiVersion: v1
kind: ConfigMap
metadata:
name: win-restic-cm
namespace: velero
data:
AWS_ACCESS_KEY_ID: "admin"
AWS_SECRET_ACCESS_KEY: "admin2675"
RESTIC_REPOSITORY: "s3:http://<MinIO-Server>:9000/aks-cluster/restic"
RESTIC_PASSWORD: "admin2675"
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: win-restic
name: win-restic
namespace: velero
spec:
selector:
matchLabels:
app: win-restic
template:
metadata:
labels:
app: win-restic
spec:
containers:
- name: win-restic
image: prasenforu/resticwin:v0.2
command:
- pwsh.exe
args:
- /Command
- while ($true) {start-sleep -s 3600}
env:
- name: POD_BACKUP_DIR_PATH
value: "c:\test"
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NODENAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: AWS_ACCESS_KEY_ID
valueFrom:
configMapKeyRef:
name: win-restic-cm
key: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
configMapKeyRef:
name: win-restic-cm
key: AWS_SECRET_ACCESS_KEY
- name: RESTIC_REPOSITORY
valueFrom:
configMapKeyRef:
name: win-restic-cm
key: RESTIC_REPOSITORY
- name: RESTIC_PASSWORD
valueFrom:
configMapKeyRef:
name: win-restic-cm
key: RESTIC_PASSWORD
volumeMounts:
- name: host-pods
mountPath: C:\host_pods
mountPropagation: HostToContainer
readOnly: true
- name: scripts
mountPath: c:\scripts\
tolerations:
- operator: Exists
nodeSelector:
beta.kubernetes.io/os: windows
volumes:
- name: host-pods
hostPath:
path: C:\var\lib\kubelet\pods
type: ""
- name: scripts
configMap:
name: restic-ps-scripts