forked from Myceliandre/myc-manage
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.2 KiB
94 lines
2.2 KiB
#!/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)\""
|