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

  1. #!/bin/bash
  2. . /etc/shlib
  3. include common
  4. include pretty
  5. is-valid-mailcow-root-dir() {
  6. local dir="$1"
  7. (
  8. [ -e "$dir" ] &&
  9. cd "$dir" &&
  10. [ -e ".git" ]
  11. )
  12. }
  13. ## find installation
  14. MAILCOW_ROOT=${MAILCOW_ROOT:-/opt/mailcow-dockerized}
  15. MYSQL_CONTAINER=${MYSQL_CONTAINER:-mailcowdockerized_mysql-mailcow_1}
  16. ## check ok
  17. is-valid-mailcow-root-dir "$MAILCOW_ROOT" || {
  18. err "Directory '$MAILCOW_ROOT' is not a valid mailcow root installation directory."
  19. echo " You might want to setup \$MAILCOW_ROOT to the proper" \
  20. "location of your mailcow root install" >&2
  21. exit 1
  22. }
  23. BACKUP_SERVER=${BACKUP_SERVER:-core-06.0k.io:10023}
  24. DOMAIN=$(cat "$MAILCOW_ROOT/.env" | grep ^MAILCOW_HOSTNAME= | cut -f 2 -d =) || {
  25. err "Couldn't find MAILCOW_ROOT in file \"$MAILCOW_ROOT/.env\"."
  26. exit 1
  27. }
  28. ## get MYSQL_ROOT_PASSWORD
  29. MYSQL_ROOT_PASSWORD=$(cat "$MAILCOW_ROOT/.env" | grep ^DBROOT= | cut -f 2 -d =) || {
  30. err "Couldn't find DBROOT in file \"$MAILCOW_ROOT/.env\"."
  31. exit 1
  32. }
  33. container_id=$(docker ps -f name="$MYSQL_CONTAINER" --format "{{.ID}}")
  34. if [ -z "$container_id" ]; then
  35. err "Couldn't find docker container named '$MYSQL_CONTAINER'."
  36. exit 1
  37. fi
  38. export MYSQL_ROOT_PASSWORD
  39. export MYSQL_CONTAINER
  40. export BACKUP_SERVER
  41. export DOMAIN
  42. (
  43. cd /srv/charm-store/rsync-backup
  44. bash ./hooks/install.d/60-install.sh
  45. ) || {
  46. echo "rsync-backup failed to install."
  47. exit 1
  48. }
  49. (
  50. cd /srv/charm-store/mysql
  51. bash ./hooks/install.d/60-backup.sh
  52. ) || {
  53. echo "mysql dump failed to install."
  54. exit 1
  55. }
  56. if ! sources=$(shyaml get-values default.sources < /etc/mirror-dir/config.yml); then
  57. echo "Couldn't query 'default.sources' in '/etc/mirror-dir/config.yml'." >&2
  58. exit 1
  59. fi
  60. if ! echo "$sources" | grep "^/var/lib/docker/volumes/\*_vmail{,-attachments-vol}-\*/_data$" 2>/dev/null; then
  61. sed -i '/sources:/a\ - "/var/lib/docker/volumes/*_vmail{,-attachments-vol}-*/_data"' \
  62. /etc/mirror-dir/config.yml
  63. fi
  64. dest="$BACKUP_SERVER"
  65. dest="${dest%/*}"
  66. dest="${dest%%:*}"
  67. echo "Contacting '$dest' host, to add key in authorized key:"
  68. ssh "root@${dest}" -- compose-add-rsync-key "\"$DOMAIN\"" "\"$(cat /var/lib/rsync/.ssh/id_rsa.pub)\""