Skip to content

Clarify time until Nextcloud's maintenance mode takes effect #9184

Description

@matzzzl

In the documentation for creating nextcloud backups you suggest to enable the maintenance mode before starting with the backup process to prevent data inconsistencies.

According to my experience activating the maintenance mode does not always have immediate effect. Only after waiting the time configured in the php configuration value
opcache.revalidate_freq
you can be sure that your nextcloud instance is really running in maintenance mode.

I suggest you should clarify this in the documentation, as automated backups taken by scripts might otherwise not be consistent, if the copying of files or the creation of a database dump is started immediately after enabling Nextcloud's maintenance mode (i.e., before it is effectively enabled). Another solution might be that the
php occ maintenance:mode --on
command blocks until maintenance mode is effectively enabled.

Activity

  1. gitoffmyln commented on Feb 22, 2023

    @gitoffmyln

    sudo -u www-data php occ maintenance:mode (without the --on or --off) will respond one of two ways ...

    • Maintenance mode is currently enabled
    • Maintenance mode is currently disabled

    One option is to adjust your backup script to use this to verify it has occurred.

    As an aside, my opcache.revalidate_freq is 20 for both apache2 and cli. [edit: this is in 25.0.3] Yet, changing config.php or running occ maintenance:mode --on has an immediate affect on the other, at least in human reaction time.

  2. joshtrichards commented on Aug 20, 2023

    @joshtrichards
    Member

    Hi @matzzzl - Great suggestion. I've fielded queries from others that have come up against this too. Can you submit a PR?

  3. MichaIng commented on Nov 1, 2023

    @MichaIng
    Member

    sudo -u www-data php occ maintenance:mode (without the --on or --off) will respond one of two ways ...

    • Maintenance mode is currently enabled
    • Maintenance mode is currently disabled

    One option is to adjust your backup script to use this to verify it has occurred.

    This cannot work, as the CLI PHP instance cannot know whether the web OPcache instance has the config.php expired already or not. The command only shows how the CLI PHP instance sees that file, and as every call creates a new PHP process, hence a new OPcache instance, it will simply always show the change immediately effective, regardless of the web status.

    As an aside, my opcache.revalidate_freq is 20 for both apache2 and cli. [edit: this is in 25.0.3] Yet, changing config.php or running occ maintenance:mode --on has an immediate affect on the other, at least in human reaction time.

    There should be no OPcache enabled at all for CLI, as there is no point to create a 128 MiB (default) cache for a single CLI call. What could be done is reading the value of opcache.revalidate_freq from the PHP config file and sleep for that amount of seconds within your maintenance script(s).

    There is actually an OPcache option for defining a blacklist file containing file paths which shall not be cached. Is it probably a generally good idea to blacklist the config.php that way? I think it is not read so often that this has no large impact on performance?
    https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.blacklist-filename
    It would be actually nice to only enforce revalidation for certain files, instead of not caching them at all, so not the whole file needs to be read and compiled each time, but only the timestamp checked. But such seems to not exist.

  4. lindhe commented on Jan 15, 2025

    @lindhe

    I also got hung up on this. How is one supposed to safely take a backup unless one can reliably determine how long to wait for the maintenance mode to kick in?

    Here it says "6-7 minutes":

    maintenance mode. After waiting for 6-7 minutes for all sync clients to
    register the server is in maintenance mode stop the application and/or
    Web server that serves Nextcloud.

    This is akin to a typo, as far as I'm concerned. If the time is between 6 and 7 minutes, surely the instructions should be to always wait for 7 minutes, just to be sure.

    But from your conversation here regarding opcache.revalidate_freq, I take it that the "6-7 minutes" is not a definitive truth either. This leaves me fairy confused. 😕 Is there no reliable way to know that maintenance mode is active and that it's safe to perform a backup? If so, that's pretty upsetting for an app that claims to be "a safe home for all your data".

  5. MichaIng commented on Jan 15, 2025

    @MichaIng
    Member

    No idea what "for all sync clients to register" means. opcache.revalidate_freq is the max time until anything which checks config.php sees the maintenance mode change. The question probably is what sync clients who are currently syncing do, how often they check back about the state, respectively when the server does so and aborts active syncs. 6 - 7 minutes however seems crazy long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions