Alternative File System

Local plugins ::: local_alternative_file_system
Maintained by Eduardo Kraus
Optimize the local file transfer from the moodledata/filedir directory to cloud storage solutions such as AWS S3 or DigitalOcean Spaces. Leverage the scalability, reliability, performance, and security offered by cloud storage for your Moodle files.
Latest release:
40 sites
93 downloads
13 fans
Current versions available: 3

This plugin allows transferring all files from the moodledata/filedir directory to cloud storage.

With this plugin, it is possible to transfer files to AWS S3 or DigitalOcean Spaces (S3-compatible).

Advantages of using cloud storage instead of local files in Moodle

By transferring files to remote storage (such as AWS S3 or DigitalOcean Spaces), you gain several advantages compared to keeping files locally.

Main benefits:

  1. Server resource optimization:
    • Moving files to the cloud reduces local disk usage and simplifies server operations.
    • When combined with a CDN (when applicable), part of the traffic can be served with lower load on the Moodle server.
  2. Scalability:
    • S3/Spaces storage allows you to grow storage capacity without relying on server disk expansion.
    • Makes it easy to increase storage as demand grows, without complex hardware migrations.
  3. Reliability:
    • Cloud storage provides high availability and object durability.
    • Reduces the risk of downtime and data loss caused by disk failures on the local server.
  4. Performance:
    • S3-compatible services can be integrated with a CDN to improve file delivery, especially for users far from the server.
    • In many scenarios, this improves load times and the user experience.
  5. Security:
    • You can apply access control, policies, encryption, and access auditing at the bucket/space level.
    • By storing files remotely, you can strengthen security practices and reduce the impact of incidents on the local server.

By choosing remote storage instead of local Moodle storage, you benefit from the scalability, reliability, performance, and security offered by S3/Spaces solutions. This improves the user experience and simplifies operations in larger environments (including clustered setups).

Implementation

After installing the plugin, you must edit the config.php file and add the line below before the call to require_once( __DIR__ . '/lib/setup.php' );.

$CFG->alternative_file_system_class = "\\local_alternative_file_system\\external_file_system";

This line changes the file system class to the one provided by the plugin. Make sure it is added in the correct location in config.php for proper operation.

To complete the installation and move the objects to the cloud, follow the steps below according to the chosen service:

AWS S3

  1. Create an AWS account:
    • If you don’t already have an account, create one at aws.amazon.com.
  2. Access the AWS Console:
    • Log in to the AWS Management Console.
  3. Create an Amazon S3 bucket:
    • In the console, go to Amazon S3 and create a new bucket.
    • Choose a unique name and select the desired region.
  4. Configure access permissions:
    • Create/adjust IAM policies to allow Moodle to access the bucket with the minimum required permissions.

DigitalOcean Spaces

  1. Create a DigitalOcean account:
  2. Access the DigitalOcean Console:
    • Log in to the DigitalOcean dashboard.
  3. Create a Space:
    • In the console, go to “Spaces” and create a new Space.
    • Choose a unique name and select the desired region.
  4. Generate access keys:
    • Generate access keys/credentials with appropriate read and write permissions for the Space.

Migration

There are two main scenarios:

Scenario A) Migration from local filedir (moodledata/filedir → cloud)

  1. Configure the destination in the plugin (S3/Spaces).
  2. Use the plugin’s migration mechanisms/routines (existing scripts).

Scenario B) Import/Migration from tool_objectfs (ObjectFS → local_alternative_file_system)

At the request of users/clients, support was added to import objects stored in tool_objectfs and copy them to the destination configured in this plugin, allowing migration with minimal downtime.

How the strategy works (without stopping the site)

The migration happens in 2 phases:

Phase 1 — Moodle continues using tool_objectfs (normal production)

While Moodle is configured with:

$CFG->alternative_file_system_class = "\\tool_objectfs\\...";
  • The site continues to read/write normally via tool_objectfs.
  • CRON runs a task that copies objects from tool_objectfs to the destination configured in local_alternative_file_system.

In other words, you “duplicate” the objects to the new destination without interrupting the site.

Phase 2 — After copying is complete, switch the AFS to this plugin

When the report indicates that migration is finished (100% / no pending items), change config.php to:

$CFG->alternative_file_system_class = "\\local_alternative_file_system\\external_file_system";

From that point on, Moodle will serve/read files directly via local_alternative_file_system.

Monitoring / Progress Report

Use the plugin’s report to track:

  • total hashes
  • migrated
  • missing
  • rate (last minutes)
  • estimated ETA

Access:

  • https://YOUR-MOODLE/local/alternative_file_system/report-migrate.php

Tip: during Phase 1 (tool_objectfs active), this report helps you decide the right moment to switch the $CFG->alternative_file_system_class.

Best practices and notes

  • Perform migrations during off-peak hours.
  • Adjust CRON batch sizes/timers according to the size of your environment.
  • After switching the AFS to this plugin, monitor the report for a period to ensure there is no “residual queue”.
  • If you use a CDN, validate headers/content-disposition according to your download policies.

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2
Screenshot #3

Contributors

Eduardo Kraus (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments

Show comments
  • Plugins bot
    Sun, 7 Apr 2024, 7:00 AM
    Approval issue created: CONTRIB-9545
  • Andrii Holdman
    Sat, 25 Jan 2025, 12:43 PM
    After adding $CFG->alternative_file_system_class = '\local_alternative_file_system\external_file_system'; before require_once( __DIR__ . '/lib/setup.php' ); in config.php I get an error: Class 'local_alternative_file_system\storages\s3\gcs_file_system' not found
    I am using moodle 4.1
    what should I do?
  • Dr.Mohd S Al-Ali
    Thu, 30 Jan 2025, 6:37 PM
    Try to use double backslash not single. It's working fine.
    $CFG->alternative_file_system_class = "\\local_alternative_file_system\\external_file_system";
    I like this plugin, it's great Job.
  • Meiseti Awan
    Tue, 11 Mar 2025, 4:41 PM
    How to delete local data that has been uploaded to s3 automatically?
  • Rod
    Thu, 27 Mar 2025, 6:14 AM
    Will this plugin work if our Moodle is hosted on Windows?
Please login to post comments