Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-64914

Asynchronous course backup webservices

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Development in progress
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.7
    • Fix Version/s: None
    • Component/s: Backup, Web Services
    • Labels:
      None
    • Testing Instructions:
      Hide

      Setup

      1. Pull the modified code
      2. Install Moodle
      3. Create a course with some content
      4. Set up webservices, including a new service and adding the functions: core_course_backup_async, core_course_backup_async_get_status, core_course_backup_list_backups

      Testing async backup webservice:

      The following curl command will start an async backup, you will need to replace the domain and webservice token to one that matches your test setup.

      curl -X POST \
      -H "Content-Type: application/x-www-form-urlencoded" \
      "http://moodle.local/webservice/rest/server.php?wstoken=97187a76113716d9c99e610a851c3599&wsfunction=core_course_backup_async&courseid=4"

      You should get output similar to the following:

      <?xml version="1.0" encoding="UTF-8" ?>
      <RESPONSE>
      <SINGLE>
      <KEY name="backupid"><VALUE>8645ab57916bff973697b469ff56119f</VALUE>
      </KEY>
      </SINGLE>
      </RESPONSE>

      Testing async backup status
      The following curl command will start an async backup, you will need to replace the domain and webservice token to one that matches your test setup. Use the backup id the was returned by the previous step.

      curl -X POST \
      -H "Content-Type: application/x-www-form-urlencoded" \
      "http://moodle.local/webservice/rest/server.php?wstoken=97187a76113716d9c99e610a851c3599&wsfunction=core_course_backup_async_get_status&backupid=020883c3fea32c0f603a947ec96e430e"

      If cron has not run you should receive a response like:

      <?xml version="1.0" encoding="UTF-8" ?>
      <RESPONSE>
      <MULTIPLE>
      <SINGLE>
      <KEY name="status"><VALUE>700</VALUE>
      </KEY>
      <KEY name="progress"><VALUE>0</VALUE>
      </KEY>
      </SINGLE>
      </MULTIPLE>
      </RESPONSE>

      If you make this call while cron is running and the course async backup is in progress you should see the status and progress change.

      • To list backups for a course*
        The following curl command will start an async backup, you will need to replace the domain and webservice token to one that matches your test setup. Use the same course ID you used for the asynchronous backup.

        curl -X POST \
        -H "Content-Type: application/x-www-form-urlencoded" \
        "http://moodle.local/webservice/rest/server.php?wstoken=97187a76113716d9c99e610a851c3599&wsfunction=core_course_backup_list_backups&courseid=4"

      You should receive a response like:

      <?xml version="1.0" encoding="UTF-8" ?>
      <RESPONSE>
      <MULTIPLE>
      <SINGLE>
      <KEY name="filename"><VALUE>backup-moodle2-course-4-small_test-20190211-1352.mbz</VALUE>
      </KEY>
      <KEY name="filesize"><VALUE>24287</VALUE>
      </KEY>
      <KEY name="downloadurl"><VALUE>http://moodle.local/webservice/pluginfile.php/13051/backup/course/backup-moodle2-course-4-small_test-20190211-1352.mbz?forcedownload=1</VALUE>
      </KEY>
      </SINGLE>
      <SINGLE>
      <KEY name="filename"><VALUE>backup-moodle2-course-4-small_test-20190211-1354.mbz</VALUE>
      </KEY>
      <KEY name="filesize"><VALUE>24306</VALUE>
      </KEY>
      <KEY name="downloadurl"><VALUE>http://moodle.local/webservice/pluginfile.php/13051/backup/course/backup-moodle2-course-4-small_test-20190211-1354.mbz?forcedownload=1</VALUE>
      </KEY>
      </SINGLE>
      <SINGLE>
      <KEY name="filename"><VALUE>backup-moodle2-course-4-small_test-20190301-1058.mbz</VALUE>
      </KEY>
      <KEY name="filesize"><VALUE>24837</VALUE>
      </KEY>
      <KEY name="downloadurl"><VALUE>http://moodle.local/webservice/pluginfile.php/13051/backup/course/backup-moodle2-course-4-small_test-20190301-1058.mbz?forcedownload=1</VALUE>
      </KEY>
      </SINGLE>
      </MULTIPLE>
      </RESPONSE>

      Show
      Setup 1. Pull the modified code 2. Install Moodle 3. Create a course with some content 4. Set up webservices, including a new service and adding the functions: core_course_backup_async, core_course_backup_async_get_status, core_course_backup_list_backups Testing async backup webservice: The following curl command will start an async backup, you will need to replace the domain and webservice token to one that matches your test setup. curl -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ "http://moodle.local/webservice/rest/server.php?wstoken=97187a76113716d9c99e610a851c3599&wsfunction=core_course_backup_async&courseid=4" You should get output similar to the following: <?xml version="1.0" encoding="UTF-8" ?> <RESPONSE> <SINGLE> <KEY name="backupid"><VALUE>8645ab57916bff973697b469ff56119f</VALUE> </KEY> </SINGLE> </RESPONSE> Testing async backup status The following curl command will start an async backup, you will need to replace the domain and webservice token to one that matches your test setup. Use the backup id the was returned by the previous step. curl -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ "http://moodle.local/webservice/rest/server.php?wstoken=97187a76113716d9c99e610a851c3599&wsfunction=core_course_backup_async_get_status&backupid=020883c3fea32c0f603a947ec96e430e" If cron has not run you should receive a response like: <?xml version="1.0" encoding="UTF-8" ?> <RESPONSE> <MULTIPLE> <SINGLE> <KEY name="status"><VALUE>700</VALUE> </KEY> <KEY name="progress"><VALUE>0</VALUE> </KEY> </SINGLE> </MULTIPLE> </RESPONSE> If you make this call while cron is running and the course async backup is in progress you should see the status and progress change. To list backups for a course* The following curl command will start an async backup, you will need to replace the domain and webservice token to one that matches your test setup. Use the same course ID you used for the asynchronous backup. curl -X POST \ -H "Content-Type: application/x-www-form-urlencoded" \ "http://moodle.local/webservice/rest/server.php?wstoken=97187a76113716d9c99e610a851c3599&wsfunction=core_course_backup_list_backups&courseid=4" You should receive a response like: <?xml version="1.0" encoding="UTF-8" ?> <RESPONSE> <MULTIPLE> <SINGLE> <KEY name="filename"><VALUE>backup-moodle2-course-4-small_test-20190211-1352.mbz</VALUE> </KEY> <KEY name="filesize"><VALUE>24287</VALUE> </KEY> <KEY name="downloadurl"><VALUE> http://moodle.local/webservice/pluginfile.php/13051/backup/course/backup-moodle2-course-4-small_test-20190211-1352.mbz?forcedownload=1 </VALUE> </KEY> </SINGLE> <SINGLE> <KEY name="filename"><VALUE>backup-moodle2-course-4-small_test-20190211-1354.mbz</VALUE> </KEY> <KEY name="filesize"><VALUE>24306</VALUE> </KEY> <KEY name="downloadurl"><VALUE> http://moodle.local/webservice/pluginfile.php/13051/backup/course/backup-moodle2-course-4-small_test-20190211-1354.mbz?forcedownload=1 </VALUE> </KEY> </SINGLE> <SINGLE> <KEY name="filename"><VALUE>backup-moodle2-course-4-small_test-20190301-1058.mbz</VALUE> </KEY> <KEY name="filesize"><VALUE>24837</VALUE> </KEY> <KEY name="downloadurl"><VALUE> http://moodle.local/webservice/pluginfile.php/13051/backup/course/backup-moodle2-course-4-small_test-20190301-1058.mbz?forcedownload=1 </VALUE> </KEY> </SINGLE> </MULTIPLE> </RESPONSE>
    • Affected Branches:
      MOODLE_37_STABLE
    • Pull Master Branch:
      master_MDL-64914_Asynchronous_course_backup_webservices

      Description

      MDL-28505 will introduce asynchronous backup and restore functionality.

      Currently there is no way to trigger asynchronous backups via webservices.  Using an external system to backup / restore and duplicate courses in Moodle is a common pattern,  so having these webservices in core will remove the reliance on plugins and custom integrations.

      The following webservices are proposed:

      • core_course_backup_async
        • Asynchronously backup a course. Course backup file will be stored in course backup area
        • Params
          • id (int): ID of the course to backup - Required
          • Options (list of objects) Duplication options - Optional
            • activities (int) Include course activites (default to 1 that is equal to yes)
            • blocks (int) Include course blocks (default to 1 that is equal to yes)
            • filters (int) Include course filters (default to 1 that is equal to yes)
            • users (int) Include users (default to 0 that is equal to no)
            • enrolments (int) Include enrolment methods (default to 1 - restore only with users)
            • role_assignments (int) Include role assignments (default to 0 that is equal to no)
            • comments (int) Include user comments (default to 0 that is equal to no)
            • userscompletion (int) Include user course completion information (default to 0 that is equal to no),
            • logs (int) Include course logs (default to 0 that is equal to no)
            • grade_histories (int) Include histories (default to 0 that is equal to no)
        • Returns
          • backupid (string) The unique ID of the backup process
      • core_course_backup_async_get_status
        • Get the status of a pending/ inprogress asynchronous course backup
        • Params
          • backupid (string) The unique ID of the backup process  - Required
        • Returns
          • status (int) The status of the backup
          • progress (float) The progress of the backup
      • core_course_backup_list_backups
        • List the available backups for a given course.
        • Params
          • id (int): ID of the course to get the list of backups - Required
        • Returns
          • Backups (list of objects)
            • filename (string) Name of the file
            • filesize (int) size of the file in bytes
            • download (url) URL to download the backup file

       

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mattp@catalyst-au.net Matt Porritt
                Reporter:
                mattp@catalyst-au.net Matt Porritt
                Participants:
                Component watchers:
                Adrian Greeve, Mihail Geshoski, Peter Dias, Juan Leyva, Jake Dallimore, Jun Pataleta, Ryan Wyllie
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: