Backing up a running Nextcloud can give you a database that remembers files the file copy missed. Closing the door for a few minutes avoids that.
Switch it on, do your work, switch it off:
docker exec --user www-data nextcloud php occ maintenance:mode --on
# dump the database, copy the data and config folders
docker exec --user www-data nextcloud php occ maintenance:mode --off
While it is on, logged in sessions are locked, including administrators, and nobody new can sign in. Sync clients wait. Users who were logged in need to refresh the browser afterwards.
In a backup script, make sure the last line runs even when something in the middle fails. In bash a trap does that:
occ() { docker exec --user www-data nextcloud php occ "$@"; }
trap 'occ maintenance:mode --off' EXIT
occ maintenance:mode --on
Otherwise one failed dump leaves your family locked out until you notice, and they will notice first.
Keep in mind that apps aren’t loaded in this mode, so occ commands that belong to apps are unavailable until you turn it off. Run those before or after. I also schedule the window for a quiet hour, since an upload that was in progress has to start again or resume on the client’s next sync.
Further reading: Nextcloud occ system commands, Nextcloud occ command
Going deeper: Guide: link Prowlarr to Sonarr and Radarr once, and stop typing indexers into every app