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.

43 lines
1.5 KiB

  1. #!/bin/bash
  2. ## When writing relation script, remember:
  3. ## - they should be idempotents
  4. ## - they can be launched while the dockers is already up
  5. ## - they are launched from the host
  6. ## - the target of the link is launched first, and get a chance to ``relation-set``
  7. ## - both side of the scripts get to use ``relation-get``.
  8. . lib/common
  9. set -e
  10. ## XXXvlab: should use container name here so that it could support
  11. ## multiple mysql
  12. label=${SERVICE_NAME}-mysql-backup
  13. DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label
  14. schedule=$(relation-get schedule)
  15. if ! echo "$schedule" | egrep '^\s*(([0-9/,*-]+\s+){4,4}[0-9/,*-]+|@[a-z]+)\s*$' >/dev/null 2>&1; then
  16. err "Unrecognized schedule '$schedule'."
  17. exit 1
  18. fi
  19. ## Warning: using '\' in heredoc will be removed in the final cron file, which
  20. ## is totally wanted: cron does not support multilines.
  21. ## Warning: 'docker -v' will use HOST directory even if launched from
  22. ## 'cron' container.
  23. file_put "$DST" <<EOF
  24. COMPOSE_LAUNCHER_OPTS=$COMPOSE_LAUNCHER_OPTS
  25. $schedule root lock $label -D -p 10 -c "\
  26. docker run --rm \
  27. --network ${PROJECT_NAME}_default \
  28. -v \"$LOCAL_DB_PASSFILE\":/root/.my.cnf \
  29. -v \"$HOST_CHARM_STORE/${CHARM_REL_PATH#${CHARM_STORE}/}/resources/bin/mysql-backup:/usr/sbin/mysql-backup\" \
  30. -v \"$SERVICE_DATASTORE/var/backups/mysql:/var/backups/mysql\" \
  31. --entrypoint mysql-backup \
  32. \"$DOCKER_BASE_IMAGE\" --host \"${SERVICE_IMAGE}\"" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${label}_script.log
  33. EOF
  34. chmod +x "$DST"