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

Add cmid option for backup and course option for restore for CLI script

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE
    • MOODLE_404_STABLE
    • MDL-79563_master_v2
    • Hide

      1. Create a test course "Test course" from Site administration > Development > Make test course.
      2. Create a course "Course for restore" and note id of the course.
      3. Open any activity in the "Test course" and note id of the course module.
      4. Open console and run the backup command with cmid: (X is cmid from 3.)

      php admin/cli/backup.php --cmid=X --destination=/tmp/

      5. Confirm, the output looks like below and the backup is for 'activity'.

      == Performing backup... ==
      Writing /tmp/backup-moodle2-activity-15-page15-20231010-1349.mbz
      Backup completed.

      6. Open console and run the backup command with cmid and courseid: (X is cmid from 3.)

      php admin/cli/backup.php --cmid=X --courseid=1 --destination=/tmp/

      7. Confirm, the output looks like below and the backup is for 'course'. (ignore cmid option if courseid is set)

      == Performing backup... ==
      Writing /tmp/backup-moodle2-course-1-moodle-master-20231102-1913.mbz
      Backup completed.

      8. Run restore command with courseid option: (Y is courseid from 2 and file is path from result of 5.)

      php admin/cli/restore_backup.php --courseid=Y --file=/tmp/backup-moodle2-activity-15-page15-20231010-1349.mbz

      9. Confirm the output looks like below and the restore to the 'course'.

      == Extracting backup file to: /var/lib/sitedata/temp/backup/restore_6524bd652ccfc ==
      == Preprocessing backup file ==
      == Restored course ID: 4 ==

      10. Go to the course page and confirm the activity is restored to the course.
      11. Run restore command with categoryid option.

      php admin/cli/restore_backup.php --categoryid=1 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz

      12. Confirm the output looks like below and the activity is restored to a new course.

      == Extracting backup file to: /var/lib/sitedata/temp/backup/restore_6543554f2600a ==
      == Preprocessing backup file ==
      == Restored course ID: 13 ==

      13. Go to the category page and confirm the activity is restored to a new course.

      14. Run restore command with categoryid and courseid option.

      php admin/cli/restore_backup.php --courseid=Y --categoryid=1 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz

      15. Confirm the output looks like below and the activity is restored to a new course.

      == Extracting backup file to: /var/lib/sitedata/temp/backup/restore_6543554f2600a ==
      == Preprocessing backup file ==
      == Restored course ID: 13 ==

      16. Go to the category page and confirm the activity is restored to a new course. (ignore courseid option if categoryid is set)

      17. Run restore command with invalid categoryid option.

      php admin/cli/restore_backup.php --categoryid=99999 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz

      18. Confirm the output looks like below:

      !!! Incorrect category ID! !!!
      !! 
      Error code: invalidcategoryid !!
      !! Stack trace: * line 85 of /admin/cli/restore_backup.php: moodle_exception thrown
       !!

      19. Run restore command with invalid courseid option.

      php admin/cli/restore_backup.php --courseid=99999 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz

      20. Confirm the output looks like below:

      !!! You are trying to use an invalid course ID !!!
      !! 
      Error code: invalidcourseid !!
      !! Stack trace: * line 89 of /admin/cli/restore_backup.php: moodle_exception thrown
       !!
      

       

      Show
      1. Create a test course "Test course" from Site administration > Development > Make test course. 2. Create a course "Course for restore" and note id of the course. 3. Open any activity in the "Test course" and note id of the course module. 4. Open console and run the backup command with cmid : (X is cmid from 3.) php admin/cli/backup.php --cmid=X --destination=/tmp/ 5. Confirm , the output looks like below and the backup is for 'activity' . == Performing backup... == Writing /tmp/backup-moodle2-activity-15-page15-20231010-1349.mbz Backup completed. 6. Open console and run the backup command with cmid and courseid : (X is cmid from 3.) php admin/cli/backup.php --cmid=X --courseid=1 --destination=/tmp/ 7. Confirm , the output looks like below and the backup is for 'course' . (ignore cmid option if courseid is set) == Performing backup... == Writing /tmp/backup-moodle2-course-1-moodle-master-20231102-1913.mbz Backup completed. 8. Run restore command with courseid option : (Y is courseid from 2 and file is path from result of 5.) php admin/cli/restore_backup.php --courseid=Y --file=/tmp/backup-moodle2-activity-15-page15-20231010-1349.mbz 9. Confirm the output looks like below and the restore to the 'course' . == Extracting backup file to: / var /lib/sitedata/temp/backup/restore_6524bd652ccfc == == Preprocessing backup file == == Restored course ID: 4 == 10. Go to the course page and confirm the activity is restored to the course . 11. Run restore command with categoryid option . php admin/cli/restore_backup.php --categoryid=1 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz 12. Confirm the output looks like below and the activity is restored to a new course . == Extracting backup file to: / var /lib/sitedata/temp/backup/restore_6543554f2600a == == Preprocessing backup file == == Restored course ID: 13 == 13. Go to the category page and confirm the activity is restored to a new course . 14. Run restore command with categoryid and courseid option . php admin/cli/restore_backup.php --courseid=Y --categoryid=1 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz 15. Confirm the output looks like below and the activity is restored to a new course . == Extracting backup file to: / var /lib/sitedata/temp/backup/restore_6543554f2600a == == Preprocessing backup file == == Restored course ID: 13 == 16. Go to the category page and confirm the activity is restored to a new course . (ignore courseid option if categoryid is set) 17. Run restore command with invalid categoryid option . php admin/cli/restore_backup.php --categoryid=99999 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz 18. Confirm the output looks like below: !!! Incorrect category ID! !!! !! Error code: invalidcategoryid !! !! Stack trace: * line 85 of /admin/cli/restore_backup.php: moodle_exception thrown !! 19. Run restore command with invalid courseid option . php admin/cli/restore_backup.php --courseid=99999 --file=/tmp/backup-moodle2-activity-27-page27-20231031-1640.mbz 20. Confirm the output looks like below: !!! You are trying to use an invalid course ID !!! !!  Error code: invalidcourseid !! !! Stack trace: * line 89 of /admin/cli/restore_backup.php: moodle_exception thrown  !!  

      Restore CLI is implemented Backup in MDL-69307 but it can't restore to the existing course.
      It always creates a new course even the backup file is for an activity.
      Backup CLI also doesn't have an activity level backup even the GUI can do it.

      It's good to have the CLI script can be used cmid (activity) option.

            tomotsuyuki Tomo Tsuyuki
            tomotsuyuki Tomo Tsuyuki
            Guillaume BARAT Guillaume BARAT
            Ilya Tregubov Ilya Tregubov
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 47 minutes
                3h 47m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.