.. _schedules: Schedule management ================================================ With these methods, you can schedule periodic operations to run in your cluster. The types of operations are currently limited to backups and best practice rules. .. container:: api-toc =================================================== ============================================= :ref:`scheduling` List jobs scheduled to run in OpsCenter. :http:method:`get-scheduled-jobs` Get the description of a scheduled job. :http:method:`get-single-scheduled-job` Schedule a job. :http:method:`create-scheduled-job` Modify a scheduled job. :http:method:`update-scheduled-job` Delete a scheduled job. :http:method:`delete-scheduled-job` =================================================== ============================================= .. _scheduling: Managing Backup Job Schedules ------------------------------- .. http:response:: Job Schedule A job schedule describes an action that OpsCenter will run periodically. There are two possible schedule types, backups and best practice rules. A job schedule has the following form: .. code-block:: js { "first_run_date": FIRST_RUN_DATE, "first_run_time": FIRST_RUN_TIME, "timezone": TIMEZONE, "interval": INTERVAL, "interval_unit": INTERVAL_UNIT "job_params": JOB_PARAMS, "id": ID, "next_run": NEXT_RUN, "last_run": LAST_RUN } :data string FIRST_RUN_DATE: A date in YYYY-MM-DD format the date for running the job. :data string FIRST_RUN_TIME: A time in hh:mm:ss format specifying the time to begin running the job. :data string TIMEZONE: The time zone, listed in the OpsCenter /meta/timezones directory, for the job schedule. For example, GMT, US/Central, US/Pacific, and US/Eastern are valid timezones. :data int INTERVAL: In conjunction with interval_unit, this controls how often the job is executed. For example, an interval of 2 and an interval_unit of weeks results in a job that will run every two weeks. :data string INTERVAL_UNIT: The unit of time for interval. Values are minutes, hours, days, or weeks. :data dict JOB_PARAMS: A dictionary that describes the job. Only the type field is required to be present in the dictionary, and its value is currently limited to backup and best-practice. Fields for this dictionary are specific to the type; for the backup type, see :http:response:`backup-job-params`. For the best-practice type see :http:response:`best-practice-job-params`. :data string ID: A unique ID that references a job schedule. Use only for retrieving a job schedule. :data string NEXT_RUN: The date and time of the next scheduled run. :data string LAST_RUN: The date and time of the last successful run. .. http:response:: Backup Job Params A JSON dictionary that describes a backup type of :http:response:`job-schedule`. This should be used as the job_params field in the :http:response:`job-schedule`. .. code-block:: js { "type": "backup", "keyspaces": KEYSPACES, "cleanup_age": CLEANUP_AGE, "cleanup_age_unit": CLEANUP_AGE_UNIT, "pre_snapshot_script": PRE_SNAPSHOT_SCRIPT, "post_snapshot_script": POST_SNAPSHOT_SCRIPT } :data list KEYSPACES: A JSON list of keyspace names that should be included in scheduled backups. An empty list or null will result in all keyspaces being included in the backups. :data int CLEANUP_AGE: (Optional) In combination with CLEANUP_AGE_UNIT, this specifies the age at which old backups should be deleted. A value of 0 will disable automatic backup cleanup. This option defaults to a value of 0, meaning automatic backup cleanups are disabled by default. :data string CLEANUP_AGE_UNIT: (Optional) The unit of time for CLEANUP_AGE. Valid values include "minutes", "hours", "days" (the default), and "weeks". :data string PRE_SNAPSHOT_SCRIPT: (Optional) The file name of a custom script to be automatically run prior to triggering each backup. This file must exist within the bin/backup-scripts/ directory where the OpsCenter agent is installed. Only letters, numbers, underscores and hyphens are permitted in the name. :data string POST_SNAPSHOT_SCRIPT: (Optional) The file name of a custom script to be automatically run after each backup is taken. The name of each file included in the backup will be passed to the script through stdin. This file must exist within the bin/backup-scripts/ directory where the OpsCenter agent is installed. Only letters, numbers, underscores and hyphens are permitted in the name. .. http:response:: Best Practice Job Params A JSON dictionary that describes a best practice rule type of :http:response:`job-schedule`. This should be used as the job_params field in the :http:response:`job-schedule`. .. code-block:: js { "type": "best-practice", "rules": RULE_LIST } :data list RULE_LIST: A JSON list of rules to run on the given schedule. At least one rule must be specified. .. http:method:: GET /{cluster_id}/job-schedules :label-name: get-scheduled-jobs :title: GET /{cluster_id}/job-schedules Retrieve a list of jobs scheduled to run in OpsCenter. Currently the only types of jobs are a scheduled backup or a best practice rule. :arg cluster_id: The ID of a cluster returned from :http:method:`get-cluster-configs`. Returns a list of :http:response:`job-schedule` objects. **Example**: .. code-block:: bash curl http://127.0.0.1:8888/Test_Cluster/job-schedules Output: .. code-block:: js [ { "first_run_date": "2012-04-19", "first_run_time": "18:00:00", "id": "19119720-115a-4f2c-862f-e10e1fb90eed", "interval": 1, "interval_unit": "days", "job_params": { "cleanup_age": 30, "cleanup_age_unit": "days", "keyspaces": [], "type": "backup" }, "last_run": "2012-04-20 18:00:00 GMT", "next_run": "2012-04-21 18:00:00 GMT", "timezone": "GMT" }, ... ] .. http:method:: GET /{cluster_id}/job-schedules/{schedule_id} :label-name: get-single-scheduled-job :title: GET /{cluster_id}/job-schedules/{schedule_id} Get the description of a scheduled job. :arg cluster_id: The ID of a cluster returned from :http:method:`get-cluster-configs`. :arg schedule_id: A unique ID of the scheduled job that matches the id of a :http:response:`job-schedule` object. Returns a :http:response:`job-schedule` object. .. http:method:: POST /{cluster_id}/job-schedules :label-name: create-scheduled-job :title: POST /{cluster_id}/job-schedules Create a new scheduled job. You can create a scheduled job to run one time in the future by specifying an interval of -1 and interval_unit of null. :arg cluster_id: The ID of a cluster returned from :http:method:`get-cluster-configs`. :body: A dictionary in the format of a :http:response:`job-schedule` describing the scheduled job to create. The id, last_run, and next_run fields should be omitted. :response 201: Job schedule created successfully Returns the ID of the newly created job. **Example** .. code-block:: bash curl -X POST http://127.0.0.1:8888/Test_Cluster/job-schedules/ -d '{ "first_run_date": "2012-05-03", "first_run_time": "18:00:00", "interval": 1, "interval_unit": "days", "job_params": { "cleanup_age": 30, "cleanup_age_unit": "days", "keyspaces": [], "type": "backup" }, "timezone": "GMT" }' Output: .. code-block:: bash "905391b7-1920-486d-a633-282f22dce604" .. http:method:: PUT /{cluster_id}/job-schedules/{schedule_id} :label-name: update-scheduled-job :title: PUT /{cluster_id}/job-schedules/{schedule_id} Update a scheduled job. :arg cluster_id: The ID of a cluster returned from :http:method:`get-cluster-configs`. :arg schedule_id: A unique ID identifying the schedule job to update. :body: A dictionary with fields from :http:response:`job-schedule` that you would like to update. :response 200: Schedule updated successfully Returns null. **Example** .. code-block:: bash curl -X PUT http://127.0.0.1:8888/Test_Cluster/job-schedules/905391b7-1920-486d-a633-282f22dce604 -d '{ "interval": "12", "interval_unit": "hours" }' .. http:method:: DELETE /{cluster_id}/job-schedules/{schedule_id} :label-name: delete-scheduled-job :title: DELETE /{cluster_id}/job-schedules/{schedule_id} Delete a scheduled job. :arg cluster_id: The ID of a cluster returned from :http:method:`get-cluster-configs`. :arg schedule_id: A unique ID identifying the schedule job to delete. :response 200: Schedule deleted successfully Returns null. **Example** .. code-block:: bash curl -X DELETE http://127.0.0.1:8888/Test_Cluster/job-schedules/905391b7-1920-486d-a633-282f22dce604