fork 0k-charms
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. label=${SERVICE_NAME}-backup
  11. DST=$CONFIGSTORE/$TARGET_SERVICE_NAME/etc/cron/$label
  12. schedule=$(relation-get schedule)
  13. if ! echo "$schedule" | egrep '^\s*(([0-9/,*-]+\s+){4,4}[0-9/,*-]+|@[a-z]+)\s*$' >/dev/null 2>&1; then
  14. err "Unrecognized schedule '$schedule'."
  15. exit 1
  16. fi
  17. exclude_dbs=$(relation-get exclude-dbs 2>/dev/null) || true
  18. exclude_dbs=$(echo "$exclude_dbs" | shyaml get-values 2>/dev/null |
  19. nspc) || true
  20. ## Warning: 'docker -v' will use HOST directory even if launched from
  21. ## 'cron' container.
  22. file_put "$DST" <<EOF
  23. COMPOSE_LAUNCHER_OPTS=$COMPOSE_LAUNCHER_OPTS
  24. $schedule root lock $label -D -p 10 -c "\
  25. docker run --rm \
  26. -u 0 \
  27. -e MONGO_HOST=${SERVICE_NAME} \
  28. -e exclude_dbs=\"$exclude_dbs\" \
  29. --network ${PROJECT_NAME}_default \
  30. -v \"$HOST_CHARM_STORE/${CHARM_REL_PATH#${CHARM_STORE}/}/resources/bin/mongo-backup:/usr/sbin/mongo-backup\" \
  31. -v \"$SERVICE_DATASTORE/var/backups/mongo:/var/backups/mongo\" \
  32. --entrypoint mongo-backup \
  33. \"$DOCKER_BASE_IMAGE\"" 2>&1 | ts '\%F \%T \%Z' >> /var/log/cron/${label}_script.log
  34. EOF
  35. chmod +x "$DST"