-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-pod.yaml
103 lines (92 loc) · 2.65 KB
/
backup-pod.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
---
kind: ConfigMap
apiVersion: v1
metadata:
name: backup-bin
namespace: {{namespace}}
data:
backup.sh: |
tgtname="{{backup_tgt}}-full-$(date +%F_%H%M%S).tar.xz"
srcdir="/mnt/backup/sources"
tgtdir="/mnt/backup/target"
bsize=$(du -abd0 $srcdir | awk '{print $1;}')
echo "Target backup file name is: '$tgtname'"
tar -C $srcdir -cf - . | pv -s ${bsize} | xz -zcT0 > $tgtdir/$tgtname
echo "Backup file '$tgtname' has been created."
restore.sh: |
srcdir="/mnt/backup/target"
tgtdir="/mnt/backup/sources"
cd $srcdir
echo "Select backup file (by a number):";
cnt=1; for c in $(ls); do if [ -f $c ]; then echo " $cnt => $c"; cnt=$((cnt+1)); fi; done
read -p "Selected file: " slf
if [ -z "$slf" ]; then
echo "File is not selected. "
echo "Exitting"
exit 223
fi
selected=""
cnt=1;
for c in $(ls); do if [ -f $c ]; then
if [ "$cnt" == "$slf" ]; then
selected=$c
break
fi
cnt=$((cnt+1))
fi; done
if [ -z "$selected" ]; then
echo "Item '$slf' does not exist in the list."
echo "Exiting"
exit 223
fi
echo ""
echo "Selected file is '$selected'. "
echo ""
echo "After continue, all current data will be deleted and will be replaced with the backup."
read -p "Really to continue? (y/...): " cntx
[ "$cntx" == "y" ] || exit 2231
srcname=$selected
bsize=$(ls -l $srcdir/$srcname | awk '{print $5;}')
cd $tgtdir
for c in $(ls); do rm -r $c/*; done
pv -s $bsize ${srcdir}/${srcname} | xz -dc | tar -C $tgtdir -x
---
apiVersion: v1
kind: Pod
metadata:
name: backup
namespace: {{namespace}}
labels:
app: backup
spec:
containers:
- name: tech
image: alpine:3.15
command: ["/bin/sh", "-c", "apk add mc bash xz bzip2 brotli pv && sleep 3600000"]
volumeMounts:
- name: hass-config-dir
mountPath: /mnt/backup/sources/hass-config-dir
- name: hass-database
mountPath: /mnt/backup/sources/hass-database
- name: mosquitto-data
mountPath: /mnt/backup/sources/mosquitto-data
- name: backup-dir
mountPath: /mnt/backup/target
- name: backup-bin
mountPath: /bb
volumes:
- name: hass-config-dir
persistentVolumeClaim:
claimName: hass-config
- name: hass-database
persistentVolumeClaim:
claimName: hass-database
- name: mosquitto-data
persistentVolumeClaim:
claimName: mosquitto-data
- name: backup-dir
hostPath:
path: /media/data1/backup/{{backup_tgt}}
- name: backup-bin
configMap:
name: backup-bin