Scheduling Cloud SQL Exports with Cloud Scheduler and Pub/Sub

PCDBE By islever Editorial Last updated

Design database backup and recovery solutions. Automate common database tasks.

Short answer

B Use Cloud Scheduler to trigger a Cloud Function through Pub/Sub to call the cloudsql.instances.export API.

Question

You work in the logistics department. Your data analysis team needs daily extracts from Cloud SQL for MySQL to train a machine learning model. The model will be used to optimize next-day routes. You need to export the data in CSV format. You want to follow Google-recommended practices. What should you do?
  1. Use Cloud Scheduler to trigger a Cloud Function that will run a select * from table(s) query to call the cloudsql.instances.export API.
  2. Use Cloud Scheduler to trigger a Cloud Function through Pub/Sub to call the cloudsql.instances.export API. Correct Answer
  3. Use Cloud Composer to orchestrate an export by calling the cloudsql.instances.export API.
  4. Use Cloud Composer to execute a select * from table(s) query and export results.

Key Takeaways

The main trap is choosing Cloud Composer for a simple scheduled task or trying to pass SQL queries directly to the export API instead of using the designated API parameters.

Learn how to schedule daily Cloud SQL for MySQL exports in CSV format using Google-recommended practices involving Cloud Scheduler, Pub/Sub, and Cloud Functions.

Common mistake: Candidates often select Cloud Composer (C) because it handles scheduling and execution, but it is overkill for a single-task workflow. Others choose A, mistakenly believing Cloud Functions can execute raw SQL to feed the export API, which is technically invalid.

Expert Analysis

The core of this question lies in distinguishing between scheduling a task and orchestrating a complex workflow. The requirement is to export data from Cloud SQL for MySQL into CSV format on a daily basis. Google’s official documentation and best practices for routine, automated exports favor the combination of Cloud Scheduler, Pub/Sub, and Cloud Functions.

Option A is incorrect because it suggests running a SELECT * query within the Cloud Function. The cloudsql.instances.export API does not accept raw SQL queries as input; it requires specific parameters like the database name, file type (CSV), and URI. Passing a SQL query would result in an API error.

Option D is also incorrect for similar reasons: Cloud Composer executing a raw SQL query does not automatically produce a CSV file via the export API, nor does it handle the scheduling mechanism natively without additional orchestration logic that mimics simpler tools.

Option C (Cloud Composer) is a common trap. While Cloud Composer (Airflow) is powerful for complex, multi-step workflows with dependencies, using it for a single, simple daily export is considered over-engineering. It introduces significant operational overhead and cost for a task that can be handled by lighter-weight services.

Option B is the correct approach. Cloud Scheduler triggers a message to a Pub/Sub topic. A Cloud Function subscribed to that topic then calls the cloudsql.instances.export API. This decoupled architecture is scalable, reliable, and aligns with Google’s recommended pattern for scheduled backups and exports, as detailed in their official guides.

Official Reference

Exam Strategy

When asked about 'Google-recommended practices' for routine automation, prefer lightweight, managed services (Scheduler + Pub/Sub + Functions) over heavy orchestration platforms (Composer) unless the workflow involves multiple dependent steps. Always verify API capabilities: the export API expects file paths and formats, not SQL queries.

Frequently Asked Questions

Can I use Cloud Functions directly without Pub/Sub?

While Cloud Functions can be triggered by HTTP or other events, Google's recommended pattern for scheduled Cloud SQL exports uses Pub/Sub as an intermediary to decouple the scheduler from the function, improving reliability and scalability.

Why not just use Cloud Composer for all scheduling tasks?

Cloud Composer is designed for complex DAGs with dependencies. For simple, independent daily tasks like exports, it adds unnecessary cost and maintenance complexity compared to Serverless options.

More PCDBE FAQ →

Community Votes

B
43%
C
43%
A
14%

43% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 13 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 13

  1. dynamic_dba 👍 4
    B. Performing a “SELECT * FROM TABLE” wouldn’t give you CSV output and that alone wouldn’t call an API. Eliminate A. There’s no need for Cloud Composer in this scenario, especially when the solution is a known combination of Cloud Scheduler, Cloud Function and a Pub/Sub Topic, which is B.
  2. sp57 👍 3
    As noted in text from this link, Cloud Function can be triggered with/without pub/sub. I think distinction between A & B is suggestion in A the API s called from query, which is not correct - the 'select query' is passed as parameter in call, so I think B is correct. "Note that we could also have a Pub/Sub Trigger configured Cloud Function get triggered by the Scheduler by using the same steps given above to create a job. Except that in the target, you will select Pub/Sub and provide the Pub/Sub Topic name. At the scheduler trigger time, the Cloud Scheduler will publish a message to the topic with the message body that you specify." https://rominirani.com/google-cloud-functions-tutorial-using-the-cloud-scheduler-to-trigger-your-functions-756160a95c43
  3. njda 👍 3
    why will someone use 3 services when it can be done using 1 service only, in this case composer. Secondly export can be for multiple tables, and ,cloud functions has a execution time limit.? C still looks most appropriate solution.
  4. GCP72 👍 3 Answered A
    A is the correct answer, PUSUB is not required for this task
  5. KennyHuang 👍 2 Answered C
    C is the recommended choice as it leverages Cloud Composer's workflow orchestration capabilities to schedule and automate the export process. By calling the cloudsql.instances.export API within the workflow, you can ensure that the data is exported from Cloud SQL for MySQL in CSV format as needed by your data analysis team.
Show 8 more comments
  1. gabrielosluz 👍 2
    The answer is letter B. Google recomends this pattern to perform this task: https://cloud.google.com/sql/docs/mysql/backup-recovery/scheduling-backups
  2. pk349 👍 2
    A: Use Cloud Scheduler to trigger a Cloud Function that will run a select from table(s) query to call the cloudsql.instances.export ** API.
  3. Nirca 👍 2 Answered B
    https://cloud.google.com/blog/topics/developers-practitioners/scheduling-cloud-sql-exports-using-cloud-functions-and-cloud-scheduler
  4. nhiguchi 👍 2 Answered C
    C is correct.
  5. KennyHuang 👍 1 Answered C
    Cloud Composer is a fully managed workflow orchestration service. It allows you to define and manage complex workflows using Apache Airflow. By using Cloud Composer, you can create a workflow that includes a task to export data from Cloud SQL for MySQL using the cloudsql.instances.export API. You can specify the export format as CSV to meet the requirement of your data analysis team. This approach provides a scalable and manageable solution for regular data exports. Therefore, option C is the recommended choice as it leverages Cloud Composer's workflow orchestration capabilities to schedule and automate the export process. By calling the cloudsql.instances.export API within the workflow, you can ensure that the data is exported from Cloud SQL for MySQL in CSV format as needed by your data analysis team.
  6. ebd62a2 👍 1 Answered B
    Cloud Scheduler, Cloud Functions and the Cloud Admin API can do this at lower cost, less maintenance and complexity. Cloud Composer for a single stage DAG is over engineering.
  7. cardareel 👍 1
    Doing a SELECT won't call the API. Pub/Sub is not needed, you are correct, the problem is the SELECT (nothing to do there).
  8. learnazureportal 👍 1
    The most accurate answer based on Google-recommended practices would be C

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to PCDBE Study Guide