How to overwrite existing course content using 'manage.py cms import'

Is it possible to use the “manage.py cms import” command to replace the contents of an existing course with a previous export of the same course? I’ve only managed to be able to create a new courserun using “manage.py cms import”. I’ve got a large number of courseruns to replace so using the CMS UI is impractical, so I’d like to use the command line importer. The exported course data from “manage.py cms export” seems to lack the original courserun info for the existing course, calling it “course” instead. “manage.py cms import” seems to lack a way to specify an existing courserun to overwrite.

Hi @kent!

I’ve been able to use the command line to import over the top of an existing course on the same Open edX service.

But I have had trouble when I try to migrate courses to a different service, like when we migrate courses off of edx.org to another self-hosted service. Sometimes these issues are content-related, for example if the videos in the course used edX’s video processing pipeline (and so are not accessible outside of edx.org), or if there are absolute links to assets or course locations in the original course content, or if the course references library items that are not on the destination service.

But simple imports and course URL changes are doable.

Importing to same course org+course+run_name location

These steps worked for me:

  1. Export the course using Studio
  2. Made a minor modification to the course display name, so I can verify that the import took effect.
  3. Unpacked the course export to /home/me/course.0/:
    $ mkdir course.0 && cd course.0
    $ tar xzf ../course.a9NldK.tar.gz
    
  4. Imported from the command line:
    (edxapp) edxapp@hostname:~/edx-platform$ ./manage.py cms import --settings=openstack \
        /edx/var/edxapp/data  /home/me/course.0/course/
    
  5. This updated the existing course at course-v1:edX+DemoX+Demo_Course

Importing to a different course org+course location

The magic here is in the unpacked course.tar.gz content itself. Using the edX DemoX course as an example:

  1. Update course/course.xml.
    In this example, I’ve changed the org from edX to OpenCraft, and the course from DemoX to DemoXPlusPlus.
    diff -ur course.0/course/course.xml course.1/course/course.xml
    --- course.0/course/course.xml	2019-10-23 03:06:19.000000000 +0000
    +++ course.1/course/course.xml	2019-10-23 03:33:03.382934795 +0000
    @@ -1 +1 @@
    -<course url_name="Demo_Course" org="edX" course="DemoX"/>
    +<course url_name="Demo_Course" org="OpenCraft" course="DemoXPlusPlus"/>
    
  2. Create the data directory for the new course, with the right permissions (depending on your deployment, the command line can throw a OSError: [Errno 13] Permission denied):
    $ sudo mkdir -p /edx/var/edxapp/data/OpenCraft/DemoXPlusPlus/Demo_Course
    $ sudo chown -R www-data: /edx/var/edxapp/data/OpenCraft/DemoXPlusPlus
    
  3. Run the import, as above:
    (edxapp) edxapp@hostname:~/edx-platform$ ./manage.py cms import --settings=openstack \
        /edx/var/edxapp/data  /home/me/course.1/course/
    
  4. This created a new course at course-v1:OpenCraft+DemoXPlusPlus+Demo_Course

Importing to a different course run_name location

The third part of the course location requires an additional step from the org+course changes described above.

  1. Update course/course.xml.
    In this example, I’ve changed the url_name from Demo_Course to `My_Demo.
    diff -ur course.0/course/course.xml course.1/course/course.xml
    --- course.0/course/course.xml	2019-10-23 03:06:19.000000000 +0000
    +++ course.2/course/course.xml	2019-10-23 03:33:03.382934795 +0000
    @@ -1 +1 @@
    -<course url_name="Demo_Course" org="edX" course="DemoX"/>
    +<course url_name="My_Demo" org="edX" course="DemoX"/>
    
  2. Move the course/<run_name>.xml file to the new run_name, e.g.:
    $ mv course.2/course/course/Demo_Course.xml course.2/course/course/My_Demo.xml
    
  3. As above, ensure the course data directory exists with the right permissions:
    $ sudo mkdir -p /edx/var/edxapp/data/edX/DemoX/My_Demo
    $ sudo chown -R www-data: /edx/var/edxapp/data/edX/DemoX/My_Demo
    
  4. Run the import, as above:
    (edxapp) edxapp@hostname:~/edx-platform$ ./manage.py cms import --settings=openstack \
        /edx/var/edxapp/data  /home/me/course.2/course/
    
  5. This created a new course at course-v1:edX+DemoX+My_Demo
1 Like

Thanks, @Jill. You’re my hero! I’ll give this a try.