Restore nextcloud without nextcloud files

Hello.
Nextcloud version : probably (20.0.4) (don’t remember)
Operating system and version_: centos 7
Apache or nginx version _: 2.4.6
PHP version: 7.3.27

Problem:
Lost root directoy with nextcloud files(/usr/share/nextcloud). Database and files are saved(other drives).
I don’t remember what version files was. Tryed 20.4 -20.7 with no luck: it’s just saying
i need update(and it stops with error).
As i understand i have mismatch apps in database and apss files. But not sure.

occ upgrade:

Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Turned on maintenance mode
Exception: Updates between multiple major versions and downgrades are unsupported.
Update failed
Maintenance mode is kept active
Resetting log level
CONFIG:
$CONFIG = array (
  'instanceid' => '***changed***',
  'trusted_domains' =>
  array (
    0 => '***changed***',
    1 => '***changed***',
  ),
  'datadirectory' => '/mnt/back/ncloud/data',
  'dbtype' => 'mysql',
  'dbhost' => 'localhost',
  'dbname' => 'ncloud',
  'dbuser' => 'ncloud',
  'dbpassword' => '***changed***',
  'dbtableprefix' => 'oc_',
  'installed' => true,
  'default_language' => 'ru',
  'default_locale' => 'ru_RU',
  'knowledgebaseenabled' => true,
  'config_is_read_only' => false,
  'log_type' => 'file',
  'logfile' => '/var/log/httpd/nextcloud.log',
  'loglevel' => 2,
  'logtimezone' => 'Asia/Ekaterinburg',
  'log_rotate_size' => 10485760,
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/usr/share/nextcloud/apps',
      'url' => '/apps',
      'writable' => true,
    ),
  ),
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'redis' =>
  array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0.0,
    'password' => '',
    'dbindex' => 0,
  ),
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'theme' => '',
);
occ config:list (apps directory):
 "apps": {
        "accessibility": {
            "enabled": "yes",
            "installed_version": "1.6.0",
            "types": ""
        },
        "activity": {
            "enable_email": "no",
            "enabled": "yes",
            "installed_version": "2.13.4",
            "types": "filesystem"
        },
        "backgroundjob": {
            "lastjob": "10"
        },
        "bruteforcesettings": {
            "enabled": "yes",
            "installed_version": "2.0.1",
            "types": ""
        },
        "calendar": {
            "enabled": "yes",
            "installed_version": "2.1.3",
            "types": ""
        },
        "cloud_federation_api": {
            "enabled": "yes",
            "installed_version": "1.3.0",
            "types": "filesystem"
        },
        "comments": {
            "enabled": "yes",
            "installed_version": "1.10.0",
            "types": "logging"
        },
        "contacts": {
            "enabled": "yes",
            "installed_version": "3.4.3",
            "types": "dav"
        },
        "contactsinteraction": {
            "enabled": "yes",
            "installed_version": "1.1.0",
            "types": "dav"
        },
        "core": {
            "backgroundjobs_mode": "cron",
            "enterpriseLogoChecked": "yes",
            "installedat": "1539242697.8188",
            "lastcron": "1613842208",
            "lastupdateResult": "[]",
            "lastupdatedat": "1613781005",
            "moveavatarsdone": "yes",
            "oc.integritycheck.checker": "[]",
            "previewsCleanedUp": "1",
            "public_files": "files_sharing\/public.php",
            "public_webdav": "dav\/appinfo\/v1\/publicwebdav.php",
            "scss.variables": "337fc7317a02c295f51d5ba2c78f8d72",
            "shareapi_allow_resharing": "yes",
            "shareapi_default_expire_date": "yes",
            "shareapi_enable_link_password_by_default": "yes",
            "shareapi_enforce_links_password": "yes",
            "theming.variables": "d41d8cd98f00b204e9800998ecf8427e",
            "updater.secret.created": "1612329449",
            "vendor": "nextcloud"
        },
        "dashboard": {
            "enabled": "yes",
            "installed_version": "7.0.0",
            "types": ""
        },
        "dav": {
            "buildCalendarReminderIndex": "yes",
            "buildCalendarSearchIndex": "yes",
            "chunks_migrated": "1",
            "enabled": "yes",
            "installed_version": "1.16.2",
            "regeneratedBirthdayCalendarsForYearFix": "yes",
            "types": "filesystem"
        },
        "duplicatefinder": {
            "enabled": "yes",
            "installed_version": "0.0.4",
            "types": ""
        },
        "federatedfilesharing": {
            "enabled": "yes",
            "installed_version": "1.10.2",
            "types": ""
        },
        "federation": {
            "enabled": "yes",
            "installed_version": "1.10.1",
            "types": "authentication"
        },
        "files": {
            "cronjob_scan_files": "500",
            "default_quota": "10 GB",
            "enabled": "yes",
            "installed_version": "1.15.0",
            "types": "filesystem"
        },
        "files_downloadactivity": {
            "enabled": "yes",
            "installed_version": "1.9.0",
            "types": "filesystem"
        },
        "files_external": {
            "enabled": "yes",
            "installed_version": "1.11.1",
            "types": "filesystem"
        },
        "files_pdfviewer": {
            "enabled": "yes",
            "installed_version": "2.0.1",
            "types": ""
        },
        "files_rightclick": {
            "enabled": "yes",
            "installed_version": "0.17.0",
            "types": ""
        },
        "files_sharing": {
            "enabled": "yes",
            "incoming_server2server_share_enabled": "no",
            "installed_version": "1.12.2",
            "lookupServerUploadEnabled": "no",
            "outgoing_server2server_share_enabled": "no",
            "types": "filesystem"
        },
        "files_texteditor": {
            "enabled": "no",
            "installed_version": "2.8.0",
            "types": ""
        },
        "files_trashbin": {
            "enabled": "yes",
            "installed_version": "1.10.1",
            "types": "filesystem,dav"
        },
        "files_versions": {
            "enabled": "yes",
            "installed_version": "1.13.0",
            "types": "filesystem,dav"
        },
        "files_videoplayer": {
            "enabled": "yes",
            "installed_version": "1.9.0",
            "types": ""
        },
        "firstrunwizard": {
            "enabled": "yes",
            "installed_version": "2.9.0",
            "types": "logging"
        },
        "gallery": {
            "enabled": "no",
            "installed_version": "18.4.0",
            "types": ""
        },
        "logreader": {
            "enabled": "yes",
            "installed_version": "2.5.0",
            "levels": "01111",
            "types": ""
        },
        "lookup_server_connector": {
            "enabled": "yes",
            "installed_version": "1.8.0",
            "types": "authentication"
        },
        "nextcloud_announcements": {
            "enabled": "yes",
            "installed_version": "1.9.0",
            "pub_date": "Thu, 24 Oct 2019 00:00:00 +0200",
            "types": "logging"
        },
        "notifications": {
            "enabled": "yes",
            "installed_version": "2.8.0",
            "types": "logging"
        },
        "oauth2": {
            "enabled": "yes",
            "installed_version": "1.8.0",
            "types": "authentication"
        },
        "password_policy": {
            "enabled": "yes",
            "enforceHaveIBeenPwned": "0",
            "installed_version": "1.10.1",
            "types": "authentication"
        },
        "photos": {
            "enabled": "yes",
            "installed_version": "1.2.3",
            "types": ""
        },
        "privacy": {
            "enabled": "yes",
            "installed_version": "1.4.0",
            "types": ""
        },
        "provisioning_api": {
            "enabled": "yes",
            "installed_version": "1.10.0",
            "types": "prevent_group_restriction"
        },
        "ransomware_detection": {
            "debug": "0",
            "enabled": "no",
            "installed_version": "0.10.0",
            "types": ""
        },
        "ransomware_protection": {
            "enabled": "yes",
            "installed_version": "1.8.0",
            "types": "logging"
        },
        "recommendations": {
            "enabled": "yes",
            "installed_version": "0.8.0",
            "types": ""
        },
        "serverinfo": {
            "enabled": "yes",
            "installed_version": "1.10.0",
            "types": ""
        },
        "settings": {
            "enabled": "yes",
            "installed_version": "1.2.0",
            "types": ""
        },
        "sharebymail": {
            "enabled": "yes",
            "installed_version": "1.10.0",
            "types": "filesystem"
        },
        "spreed": {
            "enabled": "no",
            "installed_version": "10.0.5",
            "project_access_invalidated": "1",
            "signaling_ticket_secret": "***REMOVED SENSITIVE VALUE***",
            "stun_servers": "***REMOVED SENSITIVE VALUE***",
            "types": "prevent_group_restriction"
        },
        "support": {
            "SwitchUpdaterServerHasRun": "yes",
            "enabled": "yes",
            "installed_version": "1.3.0",
            "types": "session"
        },
        "survey_client": {
            "enabled": "yes",
            "installed_version": "1.8.0",
            "last_report": "{\"id\":\"oclukaxx8wrq\",\"items\":[[\"server\",\"version\",\"20.0.7.1\"],[\"server\",\"code\",\"other\"],[\"server\",\"enable_avatars\",\"yes\"],[\"server\",\"enable_previews\",\"yes\"],[\"server\",\"memcache.local\",\"\\\\OC\\\\Memcache\\\\Redis\"],[\"server\",\"memcache.distributed\",\"none\"],[\"server\",\"asset-pipeline.enabled\",\"no\"],[\"server\",\"filelocking.enabled\",\"yes\"],[\"server\",\"memcache.locking\",\"\\\\OC\\\\Memcache\\\\Redis\"],[\"server\",\"debug\",\"no\"],[\"server\",\"cron\",\"cron\"],[\"php\",\"version\",\"7.3.23\"],[\"php\",\"memory_limit\",1073741824],[\"php\",\"max_execution_time\",0],[\"php\",\"upload_max_filesize\",2097152],[\"database\",\"type\",\"mysql\"],[\"database\",\"version\",\"5.5.45\"],[\"database\",\"size\",1607335936],[\"apps\",\"accessibility\",\"1.6.0\"],[\"apps\",\"activity\",\"2.13.4\"],[\"apps\",\"bruteforcesettings\",\"2.0.1\"],[\"apps\",\"calendar\",\"2.1.3\"],[\"apps\",\"cloud_federation_api\",\"1.3.0\"],[\"apps\",\"comments\",\"1.10.0\"],[\"apps\",\"contacts\",\"3.4.3\"],[\"apps\",\"contactsinteraction\",\"1.1.0\"],[\"apps\",\"dashboard\",\"7.0.0\"],[\"apps\",\"dav\",\"1.16.2\"],[\"apps\",\"duplicatefinder\",\"0.0.4\"],[\"apps\",\"federatedfilesharing\",\"1.10.2\"],[\"apps\",\"federation\",\"1.10.1\"],[\"apps\",\"files\",\"1.15.0\"],[\"apps\",\"files_downloadactivity\",\"1.9.0\"],[\"apps\",\"files_external\",\"1.11.1\"],[\"apps\",\"files_pdfviewer\",\"2.0.1\"],[\"apps\",\"files_rightclick\",\"0.17.0\"],[\"apps\",\"files_sharing\",\"1.12.2\"],[\"apps\",\"files_texteditor\",\"disabled\"],[\"apps\",\"files_trashbin\",\"1.10.1\"],[\"apps\",\"files_versions\",\"1.13.0\"],[\"apps\",\"files_videoplayer\",\"1.9.0\"],[\"apps\",\"firstrunwizard\",\"2.9.0\"],[\"apps\",\"gallery\",\"disabled\"],[\"apps\",\"logreader\",\"2.5.0\"],[\"apps\",\"lookup_server_connector\",\"1.8.0\"],[\"apps\",\"nextcloud_announcements\",\"1.9.0\"],[\"apps\",\"notifications\",\"2.8.0\"],[\"apps\",\"oauth2\",\"1.8.0\"],[\"apps\",\"password_policy\",\"1.10.1\"],[\"apps\",\"photos\",\"1.2.3\"],[\"apps\",\"privacy\",\"1.4.0\"],[\"apps\",\"provisioning_api\",\"1.10.0\"],[\"apps\",\"ransomware_detection\",\"disabled\"],[\"apps\",\"ransomware_protection\",\"1.8.0\"],[\"apps\",\"recommendations\",\"0.8.0\"],[\"apps\",\"serverinfo\",\"1.10.0\"],[\"apps\",\"settings\",\"1.2.0\"],[\"apps\",\"sharebymail\",\"1.10.0\"],[\"apps\",\"spreed\",\"disabled\"],[\"apps\",\"support\",\"1.3.0\"],[\"apps\",\"survey_client\",\"1.8.0\"],[\"apps\",\"systemtags\",\"1.10.0\"],[\"apps\",\"text\",\"3.1.0\"],[\"apps\",\"theming\",\"1.11.0\"],[\"apps\",\"twofactor_backupcodes\",\"1.9.0\"],[\"apps\",\"twofactor_totp\",\"5.0.0\"],[\"apps\",\"updatenotification\",\"1.10.0\"],[\"apps\",\"user_status\",\"1.0.1\"],[\"apps\",\"viewer\",\"1.4.0\"],[\"apps\",\"weather_status\",\"1.0.0\"],[\"apps\",\"workflowengine\",\"2.2.0\"],[\"stats\",\"num_files\",184007],[\"stats\",\"num_users\",25],[\"stats\",\"num_storages\",32],[\"stats\",\"num_storages_local\",4],[\"stats\",\"num_storages_home\",28],[\"stats\",\"num_storages_other\",0],[\"stats\",\"num_comments\",65],[\"stats\",\"num_comment_markers\",1],[\"stats\",\"num_systemtags\",0],[\"stats\",\"num_systemtags_mappings\",0],[\"files_sharing\",\"num_shares\",149],[\"files_sharing\",\"num_shares_user\",110],[\"files_sharing\",\"num_shares_groups\",24],[\"files_sharing\",\"num_shares_link\",9],[\"files_sharing\",\"num_shares_link_no_password\",9],[\"files_sharing\",\"num_fed_shares_sent\",0],[\"files_sharing\",\"num_fed_shares_received\",0],[\"files_sharing\",\"permissions_0_1\",\"3\"],[\"files_sharing\",\"permissions_3_1\",\"7\"],[\"files_sharing\",\"permissions_0_3\",\"3\"],[\"files_sharing\",\"permissions_3_15\",\"2\"],[\"files_sharing\",\"permissions_0_17\",\"9\"],[\"files_sharing\",\"permissions_1_17\",\"1\"],[\"files_sharing\",\"permissions_2_17\",\"5\"],[\"files_sharing\",\"permissions_0_19\",\"15\"],[\"files_sharing\",\"permissions_0_31\",\"80\"],[\"files_sharing\",\"permissions_1_31\",\"23\"],[\"files_sharing\",\"permissions_2_31\",\"1\"],[\"encryption\",\"enabled\",\"no\"],[\"encryption\",\"default_module\",\"no\"]]}",
            "last_sent": "1612458009",
            "types": ""
        },
        "systemtags": {
            "enabled": "yes",
            "installed_version": "1.10.0",
            "types": "logging"
        },
        "text": {
            "enabled": "yes",
            "installed_version": "3.1.0",
            "types": "dav"
        },
        "theming": {
            "cachebuster": "6",
            "enabled": "yes",
            "installed_version": "1.11.0",
            "logoMime": "image\/png",
            "logoheaderMime": "image\/png",
            "slogan": "***REMOVED SENSITIVE VALUE***",
            "types": "logging",
            "url": "***REMOVED SENSITIVE VALUE***"
        },
        "twofactor_backupcodes": {
            "enabled": "yes",
            "installed_version": "1.9.0",
            "types": ""
        },
        "twofactor_totp": {
            "enabled": "yes",
            "installed_version": "5.0.0",
            "types": ""
        },
        "updatenotification": {
            "bruteforcesettings": "1.6.0",
            "contacts": "3.4.3",
            "core": "20.0.7.1",
            "enabled": "yes",
            "installed_version": "1.10.0",
            "ransomware_detection": "0.10.0",
            "spreed": "7.0.4",
            "twofactor_totp": "3.0.1",
            "types": "",
            "update_check_errors": "0"
        },
        "user_status": {
            "enabled": "yes",
            "installed_version": "1.0.1",
            "types": ""
        },
        "viewer": {
            "enabled": "yes",
            "installed_version": "1.4.0",
            "types": ""
        },
        "weather_status": {
            "enabled": "yes",
            "installed_version": "1.0.0",
            "types": ""
        },
        "workflowengine": {
            "enabled": "yes",
            "installed_version": "2.2.0",
            "types": "filesystem"
        }

tail log in data folder:
"remoteAddr":"","user":"--","app":"core","method":"","url":"--","message":{"Exception":"Exception","Message":"Updates between multiple major versions and downgrades are unsupported.","Code":0,"Trace":[{"file":"/usr/share/nextcloud/lib/private/Updater.php","line":130,"function":"doUpgrade","class":"OC\\Updater","type":"->","args":["20.0.4.0","0.0.0"]},{"file":"/usr/share/nextcloud/core/Command/Upgrade.php","line":255,"function":"upgrade","class":"OC\\Updater","type":"->","args":[]},{"file":"/usr/share/nextcloud/3rdparty/symfony/console/Command/Command.php","line":255,"function":"execute","class":"OC\\Core\\Command\\Upgrade","type":"->","args":[{"__class__":"Symfony\\Component\\Console\\Input\\ArgvInput"},{"__class__":"Symfony\\Component\\Console\\Output\\ConsoleOutput"}]},{"file":"/usr/share/nextcloud/3rdparty/symfony/console/Application.php","line":1000,"function":"run","class":"Symfony\\Component\\Console\\Command\\Command","type":"->","args":[{"__class__":"Symfony\\Component\\Console\\Input\\ArgvInput"},{"__class__":"Symfony\\Component\\Console\\Output\\ConsoleOutput"}]},{"file":"/usr/share/nextcloud/3rdparty/symfony/console/Application.php","line":271,"function":"doRunCommand","class":"Symfony\\Component\\Console\\Application","type":"->","args":[{"installer":{"__class__":"OC\\Installer"},"__class__":"OC\\Core\\Command\\Upgrade"},{"__class__":"Symfony\\Component\\Console\\Input\\ArgvInput"},{"__class__":"Symfony\\Component\\Console\\Output\\ConsoleOutput"}]},{"file":"/usr/share/nextcloud/3rdparty/symfony/console/Application.php","line":147,"function":"doRun","class":"Symfony\\Component\\Console\\Application","type":"->","args":[{"__class__":"Symfony\\Component\\Console\\Input\\ArgvInput"},{"__class__":"Symfony\\Component\\Console\\Output\\ConsoleOutput"}]},{"file":"/usr/share/nextcloud/lib/private/Console/Application.php","line":215,"function":"run","class":"Symfony\\Component\\Console\\Application","type":"->","args":[{"__class__":"Symfony\\Component\\Console\\Input\\ArgvInput"},{"__class__":"Symfony\\Component\\Console\\Output\\ConsoleOutput"}]},{"file":"/usr/share/nextcloud/console.php","line":100,"function":"run","class":"OC\\Console\\Application","type":"->","args":[]},{"file":"/usr/share/nextcloud/occ","line":11,"args":["/usr/share/nextcloud/console.php"],"function":"require_once"}],"File":"/usr/share/nextcloud/lib/private/Updater.php","Line":227,"CustomMessage":"--"},"userAgent":"--","version":""}

i understand that probably easiest way is resync all, but i’ll lost versions of files.

Fixed:
added to config current vesion.

But now i have another error:


    Удаленный адрес: **deleted*
    ID Запроса: YDToa9XleT4lcpnAeC7sjwAAABQ
    Тип: Exception
    Код: 0
    Сообщение: HMAC does not match.
    Файл: «/usr/share/nextcloud/lib/private/Security/Crypto.php»
    Строка: 139


Трассировка

#0 /usr/share/nextcloud/apps/twofactor_totp/lib/Service/Totp.php(138): OC\Security\Crypto->decrypt('***deleted***...')
#1 /usr/share/nextcloud/apps/twofactor_totp/lib/Provider/TotpProvider.php(98): OCA\TwoFactorTOTP\Service\Totp->validateSecret(Object(OC\User\User), '486697')
#2 /usr/share/nextcloud/lib/private/Authentication/TwoFactorAuth/Manager.php(248): OCA\TwoFactorTOTP\Provider\TotpProvider->verifyChallenge(Object(OC\User\User), '486697')
#3 /usr/share/nextcloud/core/Controller/TwoFactorChallengeController.php(197): OC\Authentication\TwoFactorAuth\Manager->verifyChallenge('totp', Object(OC\User\User), '486697')
#4 /usr/share/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(169): OC\Core\Controller\TwoFactorChallengeController->solveChallenge('totp', '486697', '/index.php/apps...')
#5 /usr/share/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(100): OC\AppFramework\Http\Dispatcher->executeController(Object(OC\Core\Controller\TwoFactorChallengeController), 'solveChallenge')
#6 /usr/share/nextcloud/lib/private/AppFramework/App.php(152): OC\AppFramework\Http\Dispatcher->dispatch(Object(OC\Core\Controller\TwoFactorChallengeController), 'solveChallenge')
#7 /usr/share/nextcloud/lib/private/Route/Router.php(309): OC\AppFramework\App::main('OC\\Core\\Control...', 'solveChallenge', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
#8 /usr/share/nextcloud/lib/base.php(1008): OC\Route\Router->match('/login/challeng...')
#9 /usr/share/nextcloud/index.php(37): OC::handleRequest()
#10 {main}

occ twofactorauth:disable <username> totp - fixed the issue