-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrestore.sh
More file actions
122 lines (100 loc) ยท 4.02 KB
/
restore.sh
File metadata and controls
122 lines (100 loc) ยท 4.02 KB
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
#!/bin/bash
###############################
# #
# Mailcow Borg Restore #
# #
###############################
# Author: Matthis B. #
# Created: 20201106 #
# Lastchange: 20201107 #
###############################
# Changelog: #
# - 20201106: init #
# - 20201107: small changes #
###############################
#
# Settings
#
dockerDir="/opt/mailcow-dockerized" # path to docker-compose.yml
restoreVolumesFrom="/path/to/extracted/borgbackup" # path to EXTRACTED backup directory
restoreVolumesTo="/var/lib/docker/volumes" # path to volumes directory
dirnameVMail="mailcowdockerized_vmail-vol-1"
dirnameCrypt="mailcowdockerized_crypt-vol-1"
dirnameRedis="mailcowdockerized_redis-vol-1"
dirnameRSpamd="mailcowdockerized_rspamd-vol-1"
dirnamePostfix="mailcowdockerized_postfix-vol-1"
dirnameMySQL="mailcowdockerized_mysql-vol-1"
#
# Pre-Restore
#
if [[ "$(id -u)" != "0" ]] ; then
echo "- ERROR: no root!"
exit 1
fi
if [[ ! -d "${dockerDir}" ]] ; then
echo "- ERROR: docker directory does not exist (${dockerDir})!"
exit 1
fi
if [[ ! -d "${restoreVolumesFrom}" ]] ; then
echo "- ERROR: directory to restore data from does not exist (${restoreVolumesFrom})!"
exit 1
fi
if [[ ! -d "${restoreVolumesTo}" ]] ; then
echo "- ERROR: volumes directory does not exist (${restoreVolumesTo})!"
echo "- HINT: before running this script you have to install and start+stop mailcow once!"
exit 1
fi
volumeDirs=("$dirnameVMail" "$dirnameCrypt" "$dirnameRedis" "$dirnameRSpamd" "$dirnamePostfix" "$dirnameMySQL")
for dir in "${volumeDirs[@]}" ; do
dir="${restoreVolumesTo}/${dir}"
if [[ ! -d "$dir" ]] ; then
echo "- ERROR: volume directory does not exist (${dir})!"
echo "- HINT: before running this script you have to install and start+stop mailcow once!"
exit 1
fi
done
#
# Restore
#
echo "- start restoring data"
echo
echo "-- vmail"
echo "--- ${restoreVolumesFrom}${restoreVolumesTo}/${dirnameVMail}/ -> ${restoreVolumesTo}/${dirnameVMail}/"
rm -rf "${restoreVolumesTo}/${dirnameVMail}/"*
rsync -axh --stats "${restoreVolumesFrom}${restoreVolumesTo}/${dirnameVMail}/" "${restoreVolumesTo}/${dirnameVMail}/"
echo
echo "-- crypt"
echo "--- ${restoreVolumesFrom}${restoreVolumesTo}/${dirnameCrypt}/ -> ${restoreVolumesTo}/${dirnameCrypt}/"
rm -rf "${restoreVolumesTo}/${dirnameCrypt}/"*
rsync -axh --stats "${restoreVolumesFrom}${restoreVolumesTo}/${dirnameCrypt}/" "${restoreVolumesTo}/${dirnameCrypt}/"
echo
echo "-- redis"
echo "--- ${restoreVolumesFrom}${restoreVolumesTo}/${dirnameRedis}/ -> ${restoreVolumesTo}/${dirnameRedis}/"
rm -rf "${restoreVolumesTo}/${dirnameRedis}/"*
rsync -axh --stats "${restoreVolumesFrom}${restoreVolumesTo}/${dirnameRedis}/" "${restoreVolumesTo}/${dirnameRedis}/"
echo
echo "-- rspamd"
echo "--- ${restoreVolumesFrom}${restoreVolumesTo}/${dirnameRSpamd}/ -> ${restoreVolumesTo}/${dirnameRSpamd}/"
rm -rf "${restoreVolumesTo}/${dirnameRSpamd}/"*
rsync -axh --stats "${restoreVolumesFrom}${restoreVolumesTo}/${dirnameRSpamd}/" "${restoreVolumesTo}/${dirnameRSpamd}/"
echo
echo "-- postfix"
echo "--- ${restoreVolumesFrom}${restoreVolumesTo}/${dirnamePostfix}/ -> ${restoreVolumesTo}/${dirnamePostfix}/"
rm -rf "${restoreVolumesTo}/${dirnamePostfix}/"*
rsync -axh --stats "${restoreVolumesFrom}${restoreVolumesTo}/${dirnamePostfix}/" "${restoreVolumesTo}/${dirnamePostfix}/"
echo
echo "-- mysql"
echo "--- ${restoreVolumesFrom}${restoreVolumesTo}/${dirnameMySQL}/_data/tmp_backup/ -> ${restoreVolumesTo}/${dirnameMySQL}/_data/"
rm -rf "${restoreVolumesTo}/${dirnameMySQL}/"*
rsync -axh --stats "${restoreVolumesFrom}${restoreVolumesTo}/${dirnameMySQL}/_data/tmp_backup/" "${restoreVolumesTo}/${dirnameMySQL}/_data/"
echo
echo "-- mailcow"
echo "--- ${restoreVolumesFrom}/${dockerDir}/ -> ${dockerDir}/"
rsync -axh --stats "${restoreVolumesFrom}${dockerDir}/" "${dockerDir}/"
#
# Pre-Restore
#
echo
echo "- Done!"
echo "- You should be able to start your mailcow as usual (docker-compose up -d)."
echo "- Have fun :)"