So basically the database is lost/broken and no working backup of it is there? I recommend using ownBackup to avoid this, which stores a series of database backups inside the data directory.
Yes in this case just using old nextcloud directory and data directory and do files:scan --all would rebuild the files database, but shares, several settings, contacts and calendars in case will be lost. Of course the letter ones could be restored by the contacts/calendar clients. Just be sure to export them first, in case the empty server calendar/contacts databases will override the full ones on client side.
In case you use the old config.php, you need to set “installed => false” to be able to reinstall and rebuild the skeleton user database.