Py2neo issue still affecting v14.2.5 release

Hello @regis thank you for information but i have installed tutor 14.2.5 but the error still same with pyno 2 is there any information for fixed or some documentation?

Did you run tutor local launch? If not, what command did you run?

with that comand but Py2neo is still missing from docker build openedx

tutor local quickstart

If I understand correctly, the command that is failing is tutor images build openedx, right? What is the output of that command?

hello @regis, After I used this command successfully to rebuild openedx, can I change this course link
Here’s the detail :

I use the binary link version which matches the domain, but if I use the pip link version it doesn’t match the domain I installed in the config.yml. Is there a way to change it to match the domain I installed?

I apologize if my question is off topic

@Caesario_Satriatama Yes, that question is off topic. Please create a new topic. Add as much information as you can, as I have trouble figuring out exactly what you want to achieve.

here’s error after build image openedx

> [production 22/28] RUN ./manage.py cms --settings=tutor.i18n compilejsi18n:
2.652 Traceback (most recent call last):
2.652   File "/openedx/edx-platform/cms/djangoapps/coursegraph/tasks.py", line 20, in <module>
2.652     from py2neo.matching import NodeMatcher
2.652 ModuleNotFoundError: No module named 'py2neo.matching'
2.652 
2.652 During handling of the above exception, another exception occurred:
2.652 
2.652 Traceback (most recent call last):
2.652   File "./manage.py", line 103, in <module>
2.652     startup.run()
2.652   File "/openedx/edx-platform/cms/startup.py", line 20, in run
2.652     django.setup()
2.652   File "/openedx/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
2.652     apps.populate(settings.INSTALLED_APPS)
2.652   File "/openedx/venv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
2.652     app_config = AppConfig.create(entry)
2.652   File "/openedx/venv/lib/python3.8/site-packages/django/apps/config.py", line 212, in create
2.652     mod = import_module(mod_path)
2.652   File "/opt/pyenv/versions/3.8.12/lib/python3.8/importlib/__init__.py", line 127, in import_module
2.652     return _bootstrap._gcd_import(name[level:], package, level)
2.652   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2.652   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2.652   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2.652   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2.652   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
2.652   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2.652   File "/openedx/edx-platform/cms/djangoapps/coursegraph/apps.py", line 11, in <module>
2.652     class CoursegraphConfig(AppConfig):
2.652   File "/openedx/edx-platform/cms/djangoapps/coursegraph/apps.py", line 17, in CoursegraphConfig
2.652     from cms.djangoapps.coursegraph import tasks
2.652   File "/openedx/edx-platform/cms/djangoapps/coursegraph/tasks.py", line 22, in <module>
2.652     from py2neo import NodeMatcher
2.652 ImportError: cannot import name 'NodeMatcher' from 'py2neo' (/openedx/venv/lib/python3.8/site-packages/py2neo/__init__.py)
------
Dockerfile:187
--------------------
 185 |     # the downloaded locales.
 186 |     RUN ./manage.py lms --settings=tutor.i18n compilejsi18n
 187 | >>> RUN ./manage.py cms --settings=tutor.i18n compilejsi18n
 188 |     
 189 |     # Copy scripts
--------------------
ERROR: failed to solve: process "/bin/sh -c ./manage.py cms --settings=tutor.i18n compilejsi18n" did not complete successfully: exit code: 1
Error: Command failed with status 1: docker build -t docker.io/overhangio/openedx:14.2.5 /home/iceidev/.local/share/tutor/env/build/openedx

@Caesario_Satriatama Please paste here the full output of tutor images build openedx.

hello @regis
here’s detail :

tutor images build openedx
⚠️  Failed to enable plugin 'discovery': plugin 'discovery' is not installed.
⚠️  Failed to enable plugin 'forum': plugin 'forum' is not installed.
⚠️  Failed to enable plugin 'mfe': plugin 'mfe' is not installed.
Building image docker.io/overhangio/openedx:14.2.5
docker build -t docker.io/overhangio/openedx:14.2.5 /home/iceidev/.local/share/tutor/env/build/openedx
[+] Building 610.8s (32/66)                                                             docker:default
[+] Building 610.9s (32/66)                                                             docker:default
[+] Building 878.4s (32/66)                                                             docker:default
[+] Building 878.5s (32/66)                                                             docker:default
[+] Building 1054.9s (60/66)                                                            docker:default
 => [internal] load .dockerignore                                                                 0.4s
 => => transferring context: 2B                                                                   0.0s
 => [internal] load build definition from Dockerfile                                              0.6s
 => => transferring dockerfile: 11.25kB                                                           0.0s
 => [internal] load metadata for docker.io/library/ubuntu:20.04                                   2.2s
 => [internal] load build context                                                                 0.4s
 => => transferring context: 8.97MB                                                               0.1s
 => [minimal 1/2] FROM docker.io/library/ubuntu:20.04@sha256:ed4a42283d9943135ed87d4ee34e542f7f5  0.0s
 => CACHED [minimal 2/2] RUN apt update &&     apt install -y build-essential curl git language-  0.0s
 => [python 1/4] RUN apt update &&     apt install -y libssl-dev zlib1g-dev libbz2-dev     lib  179.4s
 => [locales 1/1] RUN cd /tmp     && curl -L -o openedx-i18n.tar.gz https://github.com/openedx/o  8.1s
 => [code 1/9] RUN mkdir -p /openedx/edx-platform &&     git clone https://github.com/openedx/e  22.4s
 => [dockerize 1/1] RUN dockerize_url="https://github.com/powerman/dockerize/releases/download/v  7.4s
 => [code 2/9] WORKDIR /openedx/edx-platform                                                      0.6s
 => [code 3/9] RUN git config --global user.email "tutor@overhang.io"   && git config --global u  1.3s
 => [code 4/9] RUN curl -fsSL https://github.com/overhangio/edx-platform/commit/d667feba6c.patch  2.7s 
 => [code 5/9] RUN curl -fsSL https://github.com/overhangio/edx-platform/commit/3f0f9eed42.patch  2.1s 
 => [code 6/9] RUN curl -fsSL https://github.com/overhangio/edx-platform/commit/e16f8c0986.patch  2.0s 
 => [code 7/9] RUN curl -fsSL https://github.com/overhangio/edx-platform/commit/527b4993ae.patch  2.2s 
 => [code 8/9] RUN curl -fsSL https://github.com/overhangio/edx-platform/commit/4df942b32b.patch  1.9s 
 => [code 9/9] RUN curl -fsSL https://github.com/openedx/edx-platform/commit/b12c231bad.patch |   2.0s 
 => [python 2/4] RUN git clone https://github.com/pyenv/pyenv /opt/pyenv --branch v2.2.2 --depth  2.7s 
 => [python 3/4] RUN /opt/pyenv/bin/pyenv install 3.8.12                                        113.6s 
 => [python 4/4] RUN /opt/pyenv/versions/3.8.12/bin/python -m venv /openedx/venv                  5.1s 
 => [python-requirements  1/11] RUN apt update && apt install -y software-properties-common lib  84.4s
 => [nodejs-requirements 1/6] RUN pip install nodeenv==1.6.0                                      3.1s
 => [nodejs-requirements 2/6] RUN nodeenv /openedx/nodeenv --node=12.13.0 --prebuilt              9.2s
 => [nodejs-requirements 3/6] COPY --from=code /openedx/edx-platform/package.json /openedx/edx-p  0.9s 
 => [nodejs-requirements 4/6] COPY --from=code /openedx/edx-platform/package-lock.json /openedx/  0.7s 
 => [nodejs-requirements 5/6] WORKDIR /openedx/edx-platform                                       0.5s 
 => [nodejs-requirements 6/6] RUN npm clean-install --verbose --registry=https://registry.npmjs  39.9s 
 => [python-requirements  2/11] COPY --from=code /openedx/edx-platform /openedx/edx-platform      7.3s 
 => [python-requirements  3/11] WORKDIR /openedx/edx-platform                                     0.4s 
 => [python-requirements  4/11] RUN pip install setuptools==62.1.0 pip==22.0.4 wheel==0.37.1      6.1s
 => [python-requirements  5/11] RUN pip install https://github.com/overhangio/py2neo/releases/do  9.8s 
 => [python-requirements  6/11] RUN pip install -r ./requirements/edx/base.txt                  482.1s
 => [python-requirements  7/11] RUN pip install django-redis==5.2.0                               3.9s
 => [python-requirements  8/11] RUN pip install uwsgi==2.0.20                                    21.8s
 => [python-requirements  9/11] COPY ./requirements/ /openedx/requirements                        0.7s
 => [python-requirements 10/11] RUN cd /openedx/requirements/   && touch ./private.txt   && pip  10.5s
 => [python-requirements 11/11] RUN pip install 'openedx-scorm-xblock<15.0.0,>=14.0.0'            8.0s
 => CACHED [production  1/28] RUN apt update &&     apt install -y gettext gfortran graphviz gra  0.0s
 => CACHED [production  2/28] RUN if [ "1000" = 0 ]; then echo "app user may not be root" && fal  0.0s
 => CACHED [production  3/28] RUN useradd --home-dir /openedx --create-home --shell /bin/bash --  0.0s
 => [production  4/28] COPY --from=dockerize /usr/local/bin/dockerize /usr/local/bin/dockerize    0.6s
 => [production  5/28] COPY --chown=app:app --from=code /openedx/edx-platform /openedx/edx-platf  6.6s
 => [production  6/28] COPY --chown=app:app --from=locales /openedx/locale /openedx/locale        1.4s
 => [production  7/28] COPY --chown=app:app --from=python /opt/pyenv /opt/pyenv                   5.9s
 => [production  8/28] COPY --chown=app:app --from=python-requirements /openedx/venv /openedx/v  18.2s
 => [production  9/28] COPY --chown=app:app --from=python-requirements /openedx/requirements /op  0.9s
 => [production 10/28] COPY --chown=app:app --from=nodejs-requirements /openedx/nodeenv /openedx  6.4s
 => [production 11/28] COPY --chown=app:app --from=nodejs-requirements /openedx/edx-platform/no  14.5s
 => [production 12/28] WORKDIR /openedx/edx-platform                                              0.9s
 => [production 13/28] RUN pip install -r requirements/edx/local.in                              30.6s
 => [production 14/28] RUN mkdir -p /openedx/config ./lms/envs/tutor ./cms/envs/tutor             2.1s
 => [production 15/28] COPY --chown=app:app revisions.yml /openedx/config/                        0.8s
 => [production 16/28] COPY --chown=app:app settings/lms/*.py ./lms/envs/tutor/                   0.8s
 => [production 17/28] COPY --chown=app:app settings/cms/*.py ./cms/envs/tutor/                   0.6s
 => [production 18/28] RUN mkdir /openedx/locale/user                                             1.7s
 => [production 19/28] COPY --chown=app:app ./locale/ /openedx/locale/user/locale/                0.8s
 => [production 20/28] RUN cd /openedx/locale/user &&     django-admin compilemessages -v1        1.2s
 => [production 21/28] RUN ./manage.py lms --settings=tutor.i18n compilejsi18n                    9.7s
 => ERROR [production 22/28] RUN ./manage.py cms --settings=tutor.i18n compilejsi18n              3.8s
------
 > [production 22/28] RUN ./manage.py cms --settings=tutor.i18n compilejsi18n:
3.077 Traceback (most recent call last):
3.077   File "/openedx/edx-platform/cms/djangoapps/coursegraph/tasks.py", line 20, in <module>
3.077     from py2neo.matching import NodeMatcher
3.077 ModuleNotFoundError: No module named 'py2neo.matching'
3.077 
3.077 During handling of the above exception, another exception occurred:
3.077 
3.077 Traceback (most recent call last):
3.077   File "./manage.py", line 103, in <module>
3.077     startup.run()
3.077   File "/openedx/edx-platform/cms/startup.py", line 20, in run
3.077     django.setup()
3.077   File "/openedx/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
3.077     apps.populate(settings.INSTALLED_APPS)
3.077   File "/openedx/venv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
3.077     app_config = AppConfig.create(entry)
3.077   File "/openedx/venv/lib/python3.8/site-packages/django/apps/config.py", line 212, in create
3.077     mod = import_module(mod_path)
3.077   File "/opt/pyenv/versions/3.8.12/lib/python3.8/importlib/__init__.py", line 127, in import_module
3.077     return _bootstrap._gcd_import(name[level:], package, level)
3.077   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
3.077   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
3.077   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
3.077   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
3.077   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
3.077   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
3.077   File "/openedx/edx-platform/cms/djangoapps/coursegraph/apps.py", line 11, in <module>
3.077     class CoursegraphConfig(AppConfig):
3.077   File "/openedx/edx-platform/cms/djangoapps/coursegraph/apps.py", line 17, in CoursegraphConfig
3.077     from cms.djangoapps.coursegraph import tasks
3.077   File "/openedx/edx-platform/cms/djangoapps/coursegraph/tasks.py", line 22, in <module>
3.077     from py2neo import NodeMatcher
3.077 ImportError: cannot import name 'NodeMatcher' from 'py2neo' (/openedx/venv/lib/python3.8/site-packages/py2neo/__init__.py)
------
Dockerfile:187
--------------------
 185 |     # the downloaded locales.
 186 |     RUN ./manage.py lms --settings=tutor.i18n compilejsi18n
 187 | >>> RUN ./manage.py cms --settings=tutor.i18n compilejsi18n
 188 |     
 189 |     # Copy scripts
--------------------
ERROR: failed to solve: process "/bin/sh -c ./manage.py cms --settings=tutor.i18n compilejsi18n" did not complete successfully: exit code: 1
Error: Command failed with status 1: docker build -t docker.io/overhangio/openedx:14.2.5 /home/iceidev/.local/share/tutor/env/build/openedx

Why is the build successful on my machine, but not on yours? What changes have you made to the default? Are you able to replicate the issue on a new, blank installation of Tutor 14.2.5?

Hello @regis,

I didn’t make any changes, it was done with a fresh install and I found this problem? what are the right steps I should take?

Backup your tutor environment:

cd ~/.local/share/tutor
mv env env.backup

Then install tutor from scratch in a separate virtualenv and build the openedx image:

python -m venv /tmp/tutor
source /tmp/tutor/bin/activate
pip install tutor==14.2.5
tutor config save
tutor images build openedx

tutor plugins list
:warning: Failed to enable plugin ‘discovery’: plugin ‘discovery’ is not installed.
:warning: Failed to enable plugin ‘forum’: plugin ‘forum’ is not installed.
:warning: Failed to enable plugin ‘mfe’: plugin ‘mfe’ is not installed.

how do I install all the parts, whereas in the previous version you could install it directly, how do you move it from root?

image

with sudo :

how i can move that?

you are running some of your commands as sudo and others not, sudo is not recommended, you should run it under the user account that you want to run it as…
Plugins are installed into Python, that’s why a virtual environment is recommended so you can keep your app and system python separate, here’s some examples of the very many ways python can/may be configured:

  • /usr/lib/python3/dist-packages contains non-host-specific modules installed by the system with the package manager, for example on Ubuntu with sudo apt-get install python-numpy.
  • /usr/local/lib/python3.6/dist-packages contains modules that you installed yourself system-wide through a package manager, for example with sudo pip install numpy.
  • /home/twotwo/.local/lib/python3.6/site-packages contains modules that the user twotwo has installed in his own user directory, for example by using pip in user-mode. Those modules can of cause only be imported by twotwo, because they don’t appear in other user’s PATH variables and might not even be readable by another user.
  • /home/tutor/venv/lib/python3.11/site-packages is an example where I have created a virtual environment

Make sure you have all the python components you need such as:
apt install python3.11-full (this should include python3-pip and python3.11-venv)
and make sure you create your venv (without using sudo) under the context of your user so that the file/dir permissions are correct for your user

By appending your new venv path to your .bashrc file you can ensure your user always defaults to your venv without having to manually source it before interacting with the environment, small quality of life update :slight_smile:
export PATH=~/venv/bin:$PATH

maybe these will help get you up and running:

pip install tutor-mfe==14.0.2
pip install tutor-forum==14.0.0
pip install tutor-discovery==14.0.2

pip install tutor[full] also installs all the Tutor components, but if you are specifically trying to install older versions then this might cause mismatched versions of plugins in my experience

2 Likes

thanks you @joel.edwards and @regis,
After I tried the code myself, I finally got frustrated and experienced this problem:

iceidev@VM:~$ tutor local quickstart
Error applying action 'project:root:ready': func=<function _enable_plugins at 0x7f1d83853940> contexts=[]'
Traceback (most recent call last):
  File "/home/iceidev/.local/bin/tutor", line 8, in <module>
    sys.exit(main())
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/commands/cli.py", line 24, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "/home/iceidev/.local/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/iceidev/.local/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/iceidev/.local/lib/python3.8/site-packages/click/core.py", line 1682, in invoke
    cmd_name, cmd, args = self.resolve_command(ctx, args)
  File "/home/iceidev/.local/lib/python3.8/site-packages/click/core.py", line 1729, in resolve_command
    cmd = self.get_command(ctx, cmd_name)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/commands/cli.py", line 80, in get_command
    for command in self.iter_commands(ctx):
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/commands/cli.py", line 48, in iter_commands
    cls.ensure_plugins_enabled(ctx)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/commands/cli.py", line 61, in ensure_plugins_enabled
    hooks.Actions.PROJECT_ROOT_READY.do(ctx.params["root"])
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/hooks/actions.py", line 107, in do
    self.do_from_context(None, *args, **kwargs)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/hooks/actions.py", line 121, in do_from_context
    callback.do(
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/hooks/actions.py", line 34, in do
    self.func(*args, **kwargs)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/config.py", line 296, in _enable_plugins
    config = load_minimal(root)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/config.py", line 34, in load_minimal
    config = get_user(root)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/config.py", line 98, in get_user
    config = get_yaml_file(path)
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/config.py", line 151, in get_yaml_file
    config = serialize.load(f.read())
  File "/home/iceidev/.local/lib/python3.8/site-packages/tutor/serialize.py", line 11, in load
    return yaml.load(stream, Loader=yaml.SafeLoader)
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/composer.py", line 64, in compose_node
    if self.check_event(AliasEvent):
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/parser.py", line 449, in parse_block_mapping_value
    if not self.check_token(KeyToken, ValueToken, BlockEndToken):
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/scanner.py", line 115, in check_token
    while self.need_more_tokens():
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/scanner.py", line 152, in need_more_tokens
    self.stale_possible_simple_keys()
  File "/home/iceidev/.local/lib/python3.8/site-packages/yaml/scanner.py", line 291, in stale_possible_simple_keys
    raise ScannerError("while scanning a simple key", key.mark,
yaml.scanner.ScannerError: while scanning a simple key
  in "<unicode string>", line 70, column 1:
    -mfe
    ^
could not find expected ':'
  in "<unicode string>", line 71, column 1:
    SMTP_HOST: smtp.gmail.com
    ^

The steps I took before you helped me were trying to move the plugin from root and an error appeared,
I can’t use any tutor command to perform the action

The bad news is that I haven’t backed up the data on it. if you guys have a solution please let me know :sneezing_face:

Oops, always remember to back up a working system before you go poking around with it :upside_down_face:

I normally backup like this:
sudo tar -czf "tutor-backup-$(date +%Y-%m-%d).tgz" /home/tutor/.local/
Though there is more detailed methodology for backing up and migrating servers documented here: Making backups and migrating data — Tutor documentation

As for your other issue I’m not entirely sure but it looks like it’s referring to the config.yml file ( "- mfe appears close to line 70 on my config)

in "<unicode string>", line 70, column 1:
    -mfe
    ^
could not find expected ':'
  in "<unicode string>", line 71, column 1:
    SMTP_HOST: smtp.gmail.com
    ^

I wonder if there might be a character incorrect in there or some syntax might be off. here’s a sample from mine you can take a look at to see if yours looks any different

...
  -----END RSA PRIVATE KEY-----'
LANGUAGE_CODE: en
LMS_HOST: your.host.name
MYSQL_ROOT_PASSWORD: yoursecret
OPENEDX_MYSQL_PASSWORD: yoursecret
OPENEDX_SECRET_KEY: yoursecret
PLATFORM_NAME: YourPlatformName
PLUGINS:
- your_other_plugins
- mfe
PLUGIN_INDEXES:
- https://overhang.io/tutor/main
SMTP_HOST: smtp.gmail.com
SMTP_PASSWORD: password
SMTP_PORT: 587
SMTP_USERNAME: username
SMTP_USE_SSL: false
SMTP_USE_TLS: true

how to restore backup file? because format is tar, I always do backups this way
data Migrations

if you’re more familiar with the rsync method there’s no harm in continuing that way, it’s the officially supported method. I like to store a backup in a solid archive for storage efficiency.

Here’s some usage info for the tar command:

Compress an Entire Directory or a Single File

Use the following command to compress an entire directory or a single file on Linux. It’ll also compress every other directory inside a directory you specify — in other words, it works recursively.

tar -czvf name-of-archive.tgz /path/to/directory-or-file
Here’s what those switches actually mean:

-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful. so you can visualise the progress
-f: Allows you to specify the filename of the archive.

Let’s say you have a directory named “stuff” in the current directory and you want to save it to a file named archive.tgz. You’d run the following command:
tar -czvf archive.tgz stuff
Or, let’s say there’s a directory at /usr/local/something on the current system and you want to compress it to a file named archive.tgz. You’d run the following command:

tar -czvf archive.tgz /usr/local/something

Compress Multiple Directories or Files at Once

While tar is frequently used to compress a single directory, you could also use it to compress multiple directories, multiple individual files, or both. Just provide a list of files or directories instead of a single one. For example, let’s say you want to compress the /home/ubuntu/Downloads directory, the /usr/local/stuff directory, and the /home/ubuntu/Documents/notes.txt file. You’d just run the following command:

tar -czvf archive.tgz /home/ubuntu/Downloads /usr/local/stuff /home/ubuntu/Documents/notes.txt

Just list as many directories or files as you want to back up.

Extract a Tar File

Once you have an archive, you can extract it with the tar command. The following command will extract the contents of archive.tgz to the current directory.

tar -xzvf archive.tgz

It’s the same as the archive creation command we used above, except the -x switch replaces the -c switch. This specifies you want to extract an archive instead of create one.

You may want to extract the contents of the archive to a specific directory. You can do so by appending the -C switch to the end of the command. For example, the following command will extract the contents of the archive.tgz file to the /tmp directory.

tar -xzvf archive.tgz -C /tmp

instructions adapted from howtogeek because i was lazy to type it all out :slight_smile:

thank you for your help @joel.edwards and @regis

1 Like