If you are using Nextcloud installed with the snap package, run the following command:
sudo nextcloud.export
It'll turn on maintenance mode and dump a backup of your entire instance into a timestamped folder, something like 20240723-103102, inside /var/snap/nextcloud/common/backups/.
After the export is complete, create the .tar archive with a command like this:
sudo tar -cvf 20240723-103102_nextcloud-backup.tar /var/snap/nextcloud/common/backups/20240723-103102