Skip to content

Script Reference

This is a reference of all the scripts this project provides. Some of these scripts are used internally by other scripts and not necessarily intended for direct execution. They are listed at the bottom to make this reference easier to read.

Main Scripts

mdl backup (or mdl bk)

Usage:
  mdl backup <ENV> <container/lamp> [SOURCE] [OPTIONS]

Make a backup of a Moodle environment. This can be a container environment or a
LAMP environment, and it can be local or remote. However, the backup files will
be saved in the standard Moodle backups directory. If you want to send a backup to another
destination, use the mdl cp command to copy the backup after you've made it.

All options can be set in the environment's .env file. If you use the parameter
in your command call, that will override any value set in the .env file.

Options:
-h, --help            Show this help message and exit.
-l, --label           Label for the backup. Default is today's date. (i.e. 20251029)
-m, --modules         Which module to backup. (src, data, db)
-c, --compress        Which compression, default is bzip2. (bzip2, gzip, xz, none)
-e, --ssh-args        Additional SSH arguments to pass when using ssh.
-t, --container-tool  Which container tool to use (docker or podman).
-n, --dry-run         Show what would've happened without executing.
-v, --verbose         Provide more verbose output.

Source Options (for both LAMP and container sources):
--source-host           Hostname or IP of source.
--source-sudo           Use sudo command when connecting to source.
--source-db-name        Name of the source database.
--source-db-username    Username for source database access.
--source-db-password    Password for source database access.

Source Options (only for LAMP sources):
--source-data-path      Path on source server to data path.
--source-src-path       Path on source server to src path.

mdl box

Usage: mdl box <ENV> <ACTION> [file] [dest]

Handles file access to Box.com as online storage for backups.

Actions:
  - auth
  - refresh
  - list
  - ls
  - download
  - upload

Options:
-h, --help      Show this help message and exit.
-v, --verbose   Provide more verbose output.

Options for list/ls:
-j, --json      Output results as JSON.

mdl cli

Usage: mdl cli <ENV> <COMMAND> [ARGS...]

Executes a Moodle CLI command in the environment you specify. You don't have to provide
the .php extension of the script you want to run.

If you don't provide the command you want to run, it will list all of the available
commands provided by the environment.

Options:
-h, --help         Show this help message and exit.
-i, --interactive  Enable interactive mode while executing the command.

Examples

Enable maintenance mode:
   mdl cli $mname maintenance --enable

Disable maintenance mode:
   mdl cli $mname maintenance --disable

Reset password:
   mdl cli -i $mname reset_password

Purge cache:
   mdl cli $mname purge_caches

Get list of available commands:
   mdl cli $mname

mdl config (or mdl cfg)

Usage: mdl config <ENV> [key] [value]

Will issue a config get or set command for the Moodle environment. If you provide a key
but no value, it will get the value. If you provide the value, it will set the value.

If you do not provide a key/value pair, it will scan your environment file for valid keys
and set them. This is a convenient way to set all the keys in your environment file.

Since this command uses Moodle APIs, the environment must be started. If it isn't, the
command will exit.

Options:
-h, --help         Show this help message and exit.

mdl copy (or mdl cp)

Usage: mdl copy <ENV> <LABEL> [DEST] [OPTIONS]

Copies a Moodle backup from the local environment to another destination. This
can include a local system path, a remote server via scp, or even Box.com.

Options:
-h, --help      Show this help message and exit.
-t, --type      The type of backup to copy. (backup, fastdb)
-m, --modules   Which module to copy. (src, data, db)
-l, --label     Label to rename the new copy.
-r, --rm        Remove the source backup after copying.
-b, --box       Copy the backup to Box using credentials stored in .env file.
-n, --dry-run   Show what would've happened without executing.
-v, --verbose   Provide more verbose output.

mdl exec-sql

Usage: mdl exec-sql <ENV> <SQL FILE OR COMMAND>

Executes a SQL script in the container you specify. This makes it easy to execute a SQL
script without needing to make a connection to the MariaDB database with a SQL client.

Options:
-h, --help         Show this help message and exit.

Examples

Execute a SQL file:
   mdl exec-sql $mname /path/to/file.sql

Execute a SQL statement from a string:
   mdl exec-sql $mname "select id, username, email from mdl_user limit 5"

mdl fast-db-backup

Usage: mdl fast-db-backup <ENV> [LABEL]

Makes a fast database backup, which is just a tar archive of the raw database files. The
reason this is fast is because the archive process is faster than a database dump, and
because the restore process directly restores the database files, as opposed to the
traditional restore which saves the dump in the environment and requires the dump to be
processed by the database container on startup.

This is unsafe for production but often works fine for development purposes.

Options:
-h, --help         Show this help message and exit.

mdl fast-db-restore

Usage: mdl fast-db-restore <ENV> [LABEL]

Restores a fast database backup, just overwriting the raw database files. This is unsafe
for production. However, it can make the development cycle of restoring to a previous
state much faster; whereas you do need to restart the environment, the database will
start up instantaneously since it doesn't have to import a database dump file.

Options:
-h, --help         Show this help message and exit.

mdl info

Usage: mdl info [ENV] [FIELD] [OPTIONS]

Report information about the Moodle system environment. If you provide an
environment, it will show information about that specific environment, and if
you provide a field, it will return that specific field. Otherwise, it will
show information about the Moodle system as a whole.

Options:
-h, --help         Show this help message and exit.
-f, --format       Output format (pretty, json, ini). Default: pretty
-q, --quiet        Quiet mode. Suppress normal output.
    --no-title     Do not display the title banner.

mdl init

Usage: mdl init <ENV> [OPTIONS]

Initializes a Moodle environment and, if the system isn't initialized,
sets up the directories and configuration files for the system.

Options:
-h, --help             Show this help message and exit.
-c, --compose-file-url URL to download compose file for this system.
-f, --force            Force initialization even if already initialized.
    --no-title         Do not display the title banner.
    --skip-install     Do not install a fresh environment when setting
                       up the Moodle environment. Just allocate it.

mdl install-plugin (or mdl install-plugins)

Usage: mdl install-plugin <ENV> <PLUGIN_ZIP_FILES...> [OPTIONS]

Receives a list of zip files containing Moodle plugins, and installs them into the Moodle
environment. If the path to the zip file is a URL, it will be downloaded, but it must be a
publicly accessible URL.

Options:
-h, --help          Show this help message and exit.
-s, --skip-upgrade  Skip the Moodle upgrade after copying the plugin files.

mdl list (or mdl ls)

Usage: mdl list <ENV> [OPTIONS]

Lists available backup sets for a Moodle environment.

Options:
-h, --help      Show this help message and exit.
-b, --box       Add Box to the list of backups to list.
-q, --quiet     Only list backup labels without pretty formatting.
-t, --type      Type of backups to list, default: backup, fastdb. (backup, fastdb, box)

mdl logs

Usage: mdl logs <ENV>

Displays logs for all services for a given Moodle environment.

Options:
-h, --help         Show this help message and exit.
-f, --follow       Follow the logs in real time.

mdl remove (or mdl rm)

Usage: mdl remove <ENV> [LABEL] [OPTIONS]

Deletes/removes files for a given Moodle environment. If you specify a backup label, it
will remove the backup set instead of the Moodle environment itself. If you specify the -e
or --env option, it will remove the entire Moodle environment, not just its data.

Options:
-h, --help         Show this help message and exit.
-e, --env          Remove the entire Moodle environment, not just its data.
-s, --sys          Fully uninstall the Moodle system.

Examples

Remove Moodle environment data:
   mdl remove $mname

Remove the entire Moodle environment:
   mdl remove $mname --env

Remove just this backup set for the Moodle environment:
   mdl remove $mname 20240920

Uninstall the entire Moodle system:
   mdl remove --sys

mdl rename

Usage: mdl rename <ENV> <LABEL> <NEW_LABEL> [OPTIONS]

Renames a Moodle backup set with one label to another label. It targets all
associated files with the provided label.

Options:
-h, --help      Show this help message and exit.
-n, --dry-run   Show what would've happened without executing.
-v, --verbose   Provide more verbose output.

mdl resetpassword

Usage: mdl resetpassword <ENV> [OPTIONS...]

Interactively walks you through updating the user password. This is just a convenience
script for:

   mdl cli -i $mname reset_password

You can pass it additional parameters that reset_password.php expects.

Options:
-h, --help         Show this help message and exit.
-u, --username     Specify username to change.
-p, --password     Specify new password.

Examples

Reset password interactively:
   mdl resetpassword $mname

Reset password with no interaction:
   mdl resetpassword $mname -u admin -p 'mygr8password!'

mdl restore

Usage: mdl restore <ENV> [LABEL]

Restores a backup in the backup folder to a local Moodle environment, unless
you specify to download from Box.com with the --box option. This also will
include updating the config file for the Docker environment.

Options:
-h, --help         Show this help message and exit.
-b, --box          Use backup sets in Box instead of the local backup folder.
-x, --extract      If compressed, leave the decompressed files when done extracting them.
-r, --rm           Remove the local copy of the backup when done.

mdl start

Usage: mdl start <ENV>

Starts a Moodle environment.

Options:
-h, --help         Show this help message and exit.
-w, --wait         Pause until the environment fully starts.
-f, --follow       Jump into the environment's logs after starting.
-n, --no-start     Create the containers/volumes, but do not start.
-q, --quiet        Suppress output.

mdl status

Usage: mdl status <ENV>

Report the status of Moodle environment(s). Are they running? If so, what are their
service names and IDs and data paths? What backup sets do they have?

Options:
-h, --help         Show this help message and exit.
-b, --box          Include Box in the list of backup sets
-q, --quiet        Quiet mode. Suppress normal output.

mdl stop

Usage: mdl stop <ENV> [OPTIONS]

Stop a Moodle environment(s).

Options:
-h, --help         Show this help message and exit.
-q, --quiet        Suppress output.

mdl tunnel

Usage: mdl tunnel <ENV> <ACTION> [HOST]

Initiates a tunnel to the designated container, so that you can access a port that is not
typically exposed. For instance, this is useful for accessing the database service.

If you provide a host, it will initiate a tunnel to the host via SSH that resides in the
background until you stop the tunnel. If the remote host uses a different container tool
than your local system, you can specify it with the --container-tool option.

Valid actions: start, stop

Options:
-h, --help            Show this help message and exit.
-a, --app             Which app service to connect to (mariadb)
-p, --port            Port to tunnel (3306)
-t, --container-tool  Which container tool to use (docker or podman).
-e, --ssh-args        Additional SSH arguments to pass when using ssh.
-v, --verbose         Provide more verbose output.

mdl upgrade

Usage: mdl upgrade <ENV> [TARGETBRANCH]

Upgrades the Moodle environment to the desired Moodle version. It can also be used to
pull down the latest hot fixes of the current version you're on if you just select the
same version.

Note this script technically just cleans up and fast forwards to the Git branch for the
version you specify, then reapplies any existing customizations. When the instance is
started up, Moodle will auto-upgrade the rest of its environment when it detects the new
source code.

Options:
-h, --help         Show this help message and exit.

Internal-use Scripts

These scripts are used in this project but not necessarily needed for direct execution. Documented here just for thoroughness.

active-env.sh

Usage: mdl active-env

Returns which environment is active currently. Only returns an answer if there is a
single active environment.

Options:
-h, --help      Show this help message and exit.

calc-compose-path.sh

Usage: mdl calc-compose-path <ENV>

Looks at the version of a Moodle environment, based on its Git branch, and returns the
full path of the compose.yml file that should be used.

Options:
-h, --help      Show this help message and exit.

calc-images.sh

Downloading versions file from: https://raw.githubusercontent.com/uicpharm/mdl/refs/heads/main/versions.txt

moodle-version.sh

Usage: mdl moodle-version <ENV>

Returns the Moodle version of a given Moodle environment, based on the Git branch it is
on. It returns only the numeric portion of the branch. So, for instance, if your Moodle
instance was on MOODLE_402_STABLE, it would return 402.

Options:
-h, --help      Show this help message and exit.

select-env.sh

Usage: mdl select-env <ENV>

Used by other scripts to verify a passed in Moodle environment, and interactively ask the
user to select an environment if a valid one is not passed in. So, if you request a
non-existent environment or don't pass an environment, it will give a selection list for
the user to select their environment.

Options:
-h, --help      Show this help message and exit.

touch-env.sh

Usage: mdl touch-env <ENV>

Like the touch command in Linux, this script ensures a .env file exists for an
environment. It also populates required settings in the file if they don't exist. Used
internally by other scripts to ensure an adequate .env file is present.

Options:
-h, --help      Show this help message and exit.