Browse Source
new: [mailcow-backup-install] new script
new: [mailcow-backup-install] new script
Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>rc1
Valentin Lab
5 years ago
2 changed files with 122 additions and 165 deletions
@ -0,0 +1,94 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
. /etc/shlib |
||||
|
|
||||
|
include common |
||||
|
include pretty |
||||
|
|
||||
|
|
||||
|
is-valid-mailcow-root-dir() { |
||||
|
local dir="$1" |
||||
|
( |
||||
|
[ -e "$dir" ] && |
||||
|
cd "$dir" && |
||||
|
[ -e ".git" ] |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
## find installation |
||||
|
MAILCOW_ROOT=${MAILCOW_ROOT:-/opt/mailcow-dockerized} |
||||
|
MYSQL_CONTAINER=${MYSQL_CONTAINER:-mailcowdockerized_mysql-mailcow_1} |
||||
|
|
||||
|
|
||||
|
## check ok |
||||
|
|
||||
|
is-valid-mailcow-root-dir "$MAILCOW_ROOT" || { |
||||
|
err "Directory '$MAILCOW_ROOT' is not a valid mailcow root installation directory." |
||||
|
echo " You might want to setup \$MAILCOW_ROOT to the proper" \ |
||||
|
"location of your mailcow root install" >&2 |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
BACKUP_SERVER=${BACKUP_SERVER:-core-06.0k.io:10023} |
||||
|
DOMAIN=$(cat "$MAILCOW_ROOT/.env" | grep ^MAILCOW_HOSTNAME= | cut -f 2 -d =) || { |
||||
|
err "Couldn't find MAILCOW_ROOT in file \"$MAILCOW_ROOT/.env\"." |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
|
||||
|
## get MYSQL_ROOT_PASSWORD |
||||
|
|
||||
|
MYSQL_ROOT_PASSWORD=$(cat "$MAILCOW_ROOT/.env" | grep ^DBROOT= | cut -f 2 -d =) || { |
||||
|
err "Couldn't find DBROOT in file \"$MAILCOW_ROOT/.env\"." |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
|
||||
|
container_id=$(docker ps -f name="$MYSQL_CONTAINER" --format "{{.ID}}") |
||||
|
if [ -z "$container_id" ]; then |
||||
|
err "Couldn't find docker container named '$MYSQL_CONTAINER'." |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
|
||||
|
export MYSQL_ROOT_PASSWORD |
||||
|
export MYSQL_CONTAINER |
||||
|
export BACKUP_SERVER |
||||
|
export DOMAIN |
||||
|
|
||||
|
|
||||
|
( |
||||
|
cd /srv/charm-store/rsync-backup |
||||
|
bash ./hooks/install.d/60-install.sh |
||||
|
) || { |
||||
|
echo "rsync-backup failed to install." |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
( |
||||
|
cd /srv/charm-store/mysql |
||||
|
bash ./hooks/install.d/60-backup.sh |
||||
|
) || { |
||||
|
echo "mysql dump failed to install." |
||||
|
exit 1 |
||||
|
} |
||||
|
|
||||
|
if ! sources=$(shyaml get-values default.sources < /etc/mirror-dir/config.yml); then |
||||
|
echo "Couldn't query 'default.sources' in '/etc/mirror-dir/config.yml'." >&2 |
||||
|
exit 1 |
||||
|
fi |
||||
|
|
||||
|
if ! echo "$sources" | grep "^/var/lib/docker/volumes/\*_vmail{,-attachments-vol}-\*/_data$" 2>/dev/null; then |
||||
|
sed -i '/sources:/a\ - "/var/lib/docker/volumes/*_vmail{,-attachments-vol}-*/_data"' \ |
||||
|
/etc/mirror-dir/config.yml |
||||
|
fi |
||||
|
|
||||
|
|
||||
|
dest="$BACKUP_SERVER" |
||||
|
dest="${dest%/*}" |
||||
|
dest="${dest%%:*}" |
||||
|
|
||||
|
echo "Contacting '$dest' host, to add key in authorized key:" |
||||
|
ssh "root@${dest}" -- compose-add-rsync-key "\"$DOMAIN\"" "\"$(cat /var/lib/rsync/.ssh/id_rsa.pub)\"" |
Write
Preview
Loading…
Cancel
Save
Reference in new issue