Skip to content

[Bug]: not show files s3 primary storage #34407

Closed as not planned
Closed as not planned

Description

@edwinosky

⚠️ This issue respects the following points: ⚠️

  • This is a bug, not a question or a configuration/webserver/proxy issue.
  • This issue is not already reported on Github (I've searched it).
  • Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
  • Nextcloud Server is running on 64bit capable CPU, PHP and OS.
  • I agree to follow Nextcloud's Code of Conduct.

Bug description

Hello guys, I have more than a week dealing with a serious problem with my nextcloud installation, I tried to test many things before writing here
I have a nextcloud installation for months that I use to share content with family, friends and clients, I have been using cloudflare's R2 as primary S3 storage, everything worked great for months, until a week ago the installation is completely broken and no shows the files, if it tries to open a previously shared url if it shows the list of files but when trying to play or load them an error is shown, I already did a new installation, but when configuring S3 as primary storage it returns and breaks, it does not load the css styles of the installation, I will leave some screenshots of how it is shown

Steps to reproduce

  1. create a new installation of nextcloud version 24.0.5
  2. configure s3 as primary storage
  3. the installation is completely broken

Expected behavior

that everything works correctly as this great software does

Installation method

Community Web installer on a VPS or web space

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.0

Web server

Apache (supported)

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

Updated to a major version (ex. 22.2.3 to 23.0.1)

Are you using the Nextcloud Server Encryption module?

No response

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "158.69.0.213"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "24.0.5.1",
        "overwrite.cli.url": "http:\/\/158.69.0.213",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "skeletondirectory": "",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 6379,
            "dbindex": 5,
            "password": "***REMOVED SENSITIVE VALUE***",
            "timeout": 1.5
        },
        "theme": "",
        "loglevel": 0,
        "logfile": "\/var\/www\/vhosts\/files.log",
        "default_phone_region": "CO",
        "mail_smtpmode": "smtp",
        "mail_smtpsecure": "ssl",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtpauth": 1,
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "updater.release.channel": "stable",
        "objectstore": {
            "class": "\\OC\\Files\\ObjectStore\\S3",
            "arguments": {
                "bucket": "nextcloud",
                "autocreate": false,
                "key": "***REMOVED SENSITIVE VALUE***",
                "secret": "***REMOVED SENSITIVE VALUE***",
                "hostname": "7ea0e644ac8bc2e985b18c6d7953ef47.r2.cloudflarestorage.com",
                "port": 443,
                "use_ssl": true,
                "region": "auto",
                "use_path_style": true
            }
        },
        "filelocking.enabled": false,
        "htaccess.RewriteBase": "\/",
        "forwarded_for_headers": [
            "HTTP_X_FORWARDED_FOR"
        ],
        "enabledPreviewProviders": [
            "OC\\Preview\\MP3",
            "OC\\Preview\\TXT",
            "OC\\Preview\\MarkDown",
            "OC\\Preview\\OpenDocument",
            "OC\\Preview\\Krita",
            "OC\\Preview\\MP4",
            "OC\\Preview\\Movie",
            "OC\\Preview\\Imaginary"
        ],
        "preview_imaginary_url": "http:\/\/158.69.0.213:9000\/",
        "preview_max_x": 500,
        "preview_max_y": 500,
        "maintenance": false
    }
}

List of activated Apps

Enabled:
  - activity: 2.16.0
  - bruteforcesettings: 2.4.0
  - cloud_federation_api: 1.7.0
  - csp_editor: 1.1.0
  - dashboard: 7.4.0
  - dav: 1.22.0
  - federatedfilesharing: 1.14.0
  - federation: 1.14.0
  - files: 1.19.0
  - files_external: 1.16.1
  - files_rightclick: 1.3.0
  - files_sharing: 1.16.2
  - files_trashbin: 1.14.0
  - files_videoplayer: 1.13.0
  - logreader: 2.9.0
  - lookup_server_connector: 1.12.0
  - nextcloud_announcements: 1.13.0
  - notifications: 2.12.1
  - oauth2: 1.12.0
  - password_policy: 1.14.0
  - photos: 1.6.0
  - privacy: 1.8.0
  - provisioning_api: 1.14.0
  - serverinfo: 1.14.0
  - settings: 1.6.0
  - theming: 1.15.0
  - twofactor_backupcodes: 1.13.0
  - updatenotification: 1.14.0
  - user_status: 1.4.0
  - viewer: 1.8.0
  - workflowengine: 2.6.0
Disabled:
  - accessibility: 1.10.0
  - admin_audit
  - announcementcenter: 6.3.1
  - backup: 1.1.3
  - cfg_share_links: 2.0.0
  - circles: 24.0.1
  - comments: 1.14.0
  - contactsinteraction: 1.5.0
  - encryption
  - external: 4.0.0
  - files_pdfviewer: 2.5.0
  - files_versions: 1.17.0
  - firstrunwizard: 2.13.0
  - impersonate: 1.11.0
  - previewgenerator: 5.0.0
  - recommendations: 1.3.0
  - registration: 1.5.0
  - sharebymail: 1.14.0
  - support: 1.7.0
  - survey_client: 1.12.0
  - systemtags: 1.14.0
  - text: 3.5.1
  - user_ldap
  - user_migration: 1.1.0
  - weather_status: 1.4.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

{"reqId":"Yzr07ZAl16LwBjxqKRxiSQAAAA8","level":0,"time":"2022-10-03T14:42:54+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/dashboard/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr07ZAl16LwBjxqKRxiSQAAAA8","level":0,"time":"2022-10-03T14:42:54+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/dashboard/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr07ZAl16LwBjxqKRxiSQAAAA8","level":0,"time":"2022-10-03T14:42:54+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/dashboard/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr07ZAl16LwBjxqKRxiSQAAAA8","level":0,"time":"2022-10-03T14:42:54+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/dashboard/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr07ZAl16LwBjxqKRxiSQAAAA8","level":0,"time":"2022-10-03T14:42:54+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/dashboard/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr07ZAl16LwBjxqKRxiSQAAAA8","level":0,"time":"2022-10-03T14:42:54+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/dashboard/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::isCached 9b08-0323-icons.css isCachedCache is expired or unset","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::isCached 9b08-0323-icons.css dependencies successfully cached for 5 minutes","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr08pAl16LwBjxqKRxiTAAAABc","level":0,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"scss_cacher","method":"GET","url":"/apps/files/","message":"SCSSCacher::process ordinary check follows","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"scss_cacher"}}
{"reqId":"Yzr0800Mag8KBHrb-gRt2wAAAQ0","level":3,"time":"2022-10-03T14:42:59+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"PHP","method":"GET","url":"/css/files_sharing/9b08-0323-icons.css?v=7b9e9931979bc025b39295473ae35fe7-9b088ce7-16","message":"fopen(httpseek://): Failed to open stream: "OC\\Files\\Stream\\SeekableHttpStream::stream_open" call failed at /var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/Stream/SeekableHttpStream.php#67","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","exception":{"Exception":"Error","Message":"fopen(httpseek://): Failed to open stream: "OC\\Files\\Stream\\SeekableHttpStream::stream_open" call failed at /var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/Stream/SeekableHttpStream.php#67","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/Stream/SeekableHttpStream.php","line":67,"function":"fopen"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/ObjectStore/S3ObjectTrait.php","line":88,"function":"open","class":"OC\\Files\\Stream\\SeekableHttpStream","type":"::"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/ObjectStore/ObjectStoreStorage.php","line":312,"function":"readObject","class":"OC\\Files\\ObjectStore\\S3","type":"->"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/Storage/Common.php","line":197,"function":"fopen","class":"OC\\Files\\ObjectStore\\ObjectStoreStorage","type":"->"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php","line":247,"function":"file_get_contents","class":"OC\\Files\\Storage\\Common","type":"->"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Files/Storage/Wrapper/Availability.php","line":264,"function":"file_get_contents","class":"OC\\Files\\Storage\\Wrapper\\Wrapper","type":"->"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/AppFramework/App.php","line":172,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Route/Router.php","line":298,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/lib/base.php","line":1030,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/var/www/vhosts/158.69.0.213/nextcloud/index.php","line":36,"function":"handleRequest","class":"OC","type":"::"}],"File":"/var/www/vhosts/158.69.0.213/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"}}
{"reqId":"Yzr09ZAl16LwBjxqKRxiUQAAABM","level":1,"time":"2022-10-03T14:43:02+00:00","remoteAddr":"181.63.21.109","user":"admin","app":"theming","method":"GET","url":"/apps/theming/favicon/files?v=16","message":"The image was requested to be no SVG file, but converting it to PNG failed: Zero size image string passed","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"24.0.5.1","data":{"app":"theming"}}

Additional info

image

image

Activity

  1. added
    0. Needs triage
    on Oct 3, 2022
  2. mrAceT commented on Oct 4, 2022

    @mrAceT

    Hi,

    Do you see the file-listings in your instance? (via web-interface)
    Is the data there in your S3 storage? (all 'numbered files')
    Do you see the previews? (via web-interface)

    take a good hard look at your sql-table oc_storages. When you are working completely in S3 all entries should be 'object:...' I think you may have some history with 'local:' folders.. DO NOT simply remove those entries!!

    Could you post the oc_storages info? (do anonymize the data)

    I have quite a bit of experience with NextCloud->S3, so I might just be able to help you out..

  3. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    Hi,

    Do you see the file-listings in your instance? (via web-interface) Is the data there in your S3 storage? (all 'numbered files') Do you see the previews? (via web-interface)

    take a good hard look at your sql-table oc_storages. When you are working completely in S3 all entries should be 'object:...' I think you may have some history with 'local:' folders.. DO NOT simply remove those entries!!

    Could you post the oc_storages info? (do anonymize the data)

    I have quite a bit of experience with NextCloud->S3, so I might just be able to help you out..

    hi
    I really appreciate your help, here I show you my oc_storage table
    image

    image

  4. mrAceT commented on Oct 4, 2022

    @mrAceT

    please answer:

    1. Do you see the file-listings in your instance? (via web-interface)
    2. Is the data there in your S3 storage? (all 'numbered files')
    3. Do you see the previews? (via web-interface)
  5. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    the web interface does not show the files, not previews, it does not even try to upload them, in cloudflare R2 I have more than 1TB of data but I cannot access it without nextcloud

  6. mrAceT commented on Oct 4, 2022

    @mrAceT

    you have
    28: object::user::sonya => GOOD
    49: home::sonya => local storage! => NOT good

    you have
    1: local::/var.... => NOT good!
    29: object::store.. => GOOD!

    check your oc_filecache and take a good look at at the storage ID's

    I have had trouble with migrating to S3 storage.. and have written a migration tool to local (take a look at: lukasmu/nextcloud-s3-to-disk-migration#6) and later have built the reverse back to s3..

    what you will need to do is first make backups! Of your data.. of your SQL.

    Did you have a separate storage config? (that was part of my trouble..)

    Is there data in your LOCAL data folder? (besides the default stuff)

    check your oc_filecache, are there storage id's attached to number 1? and 49?

    This BRUTE FORCE approach might work (but do make backups..........):

    • go to maintenance mode (beyond important)
    • check your config => is all set to S3?
    • remove the local storages in oc_storages (local.. home..)
    • remove all the local storage references in your oc_filecache
    • go out of maintenance mode

    This Q & D approach might work.. (but do make backups..........)

    The problem is you are now "in limbo" things are set to local AND S3.. Nextcloud seems to prefer local.. resulting in you not seeing S3..

  7. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    If I already have a backup of my database, I use plesk so it is very easy, and I also have the R2 bucket backed up in another bucket
    I will try to carry out the steps that you indicate in oc_storage and in oc_filecache as soon as I finish I come back here to talk to you about the results

  8. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    hi @mrAceT
    I already deleted the oc_storage entries, the error is still not fixed, now I ask you in oc_filecache I have more than half a million entries, will I be able to delete them all?

    image

    image

  9. mrAceT commented on Oct 4, 2022

    @mrAceT

    oc_filecache I have more than half a million entries, will I be able to delete them all?

    NO!!

    In contrary to local storage, S3 storage can NOT rebuild itself via the data in S3 (that should be possible, but for some reason NextCloud has decided to use the cryptic numbers, I have asked about this in the forum, but to my knowledge no one has ever given a good answer)

    check your oc_filecache, are there storage id's attached to number 1? and 49?
    remove all the local storage references in your oc_filecache

    With that last sentence I ment the numbers of all those 'home & local' ID's.. if you would remove those, all data in there should refer to S3-data.. So for Sonya.. how many entries are there in oc_filecache with storage ID 28 ? Does that "feel right"?

  10. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    delete the oc_filecache entries with ID 1 ID 28 and ID 49, it does not solve the problem either, I remember that it happened to me about three months ago and I managed to solve it with a command that I execute in the occ binary, that command was written by someone in the official forum but I couldn't find it
    I have been thinking about using the script that you recommended above but I think I will need enough storage space, that implies changing vps

  11. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    i'm pretty sure my problem lies with the database because i install a clean instance with s3 and it works fine, it just breaks when i import the database

  12. mrAceT commented on Oct 4, 2022

    @mrAceT

    delete the oc_filecache entries with ID 1 ID 28 and ID 49, it does not solve the problem either, I remember that it happened to me about three months ago and I managed to solve it with a command that I execute in the occ binary, that command was written by someone in the official forum but I couldn't find it I have been thinking about using the script that you recommended above but I think I will need enough storage space, that implies changing vps

    Oh dear.. number 28 are the entries for OBJECT->S3.. do you understand the structure of the numbers? You need to remove the NOT object-numbers

  13. edwinosky commented on Oct 4, 2022

    @edwinosky
    Author

    The truth is that all the data that matters to me is in the admin account, and since I share it with other users, I can delete the other user accounts without problems.

    Is there any way to do a kind of cleanup to the database without touching the admin data?

  14. mrAceT commented on Oct 4, 2022

    @mrAceT

    The truth is that all the data that matters to me is in the admin account, and since I share it with other users, I can delete the other user accounts without problems.

    Is there any way to do a kind of cleanup to the database without touching the admin data?

    Then I'dd keep it simple.. and remove all the other accounts via the web-interface.. then you would have a nice clean oc_storage (the basis S3 entry and that one user?. Then remove all but those two numbers form the oc_filecache .. If nothing else has been broken, you should see all your files you'dd want to rescue in your filecache..

    Also, if the other users are "simply shares".. then you'dd not have any other files lingering in your S3 storage..

  15. 8 remaining items

  16. mrAceT commented on Oct 6, 2022

    @mrAceT

    In all honesty I do not understand why my last option did not work.. it should have..

    Do you have 1Tb of disk space available?
    I fear the only option I can think of is this:

    1. create the tables and set nextcloud up as described in my last not working solution
    2. have 1TB of space..
    3. use my S3-to-local conversion script in test mode (that uses your nextcloud S3-credentials and those two tables)

    Your data is in there.. You could create a "spin off" of my s3-to-local-script that simply creates the folder-structure with the correct file name.. In essence that is what that script does..

    If that does not work.. I could fix it for you, I'm practically certain.. but I'dd need shell access to your account with 1TB of space and access to your S3 credentials and database..
    (and in all honesty I'dd need to charge for my time.. I've got a mortgage to you know.. ;) )

  17. mrAceT commented on Oct 6, 2022

    @mrAceT

    OK.. it's past midnight and I seriously need to go to bed, but here is my "special standalone S3 > local" version for you.. I am hoping you know about 'vendor/autoload' and know how to install the Aws\S3\S3Client package..

    NEEDED:

    • S3 credentials
    • S3 data
    • SQL credentials
    • table oc_filecache
    • table oc_storages
    • table oc_mimetypes

    Set up the variables and let it rip.. My first run of I believe about 100 Gb took hours.. so be patient.. There is a progress indication.. but do be patient..

    All I'll ask for it is that you go to OpenStreetMap and look op Friesland (in The Netherlands) and remember that that's where your saviour lives ;)
    Oh, if I/we ever go to Venezuela, you ow me a beer ;)

    [update] $NR_OF_COPY_ERRORS_OK has no real use in this case => removed

    <?php
    # runuser -u [user] -- composer require aws/aws-sdk-php
    use Aws\S3\S3Client;
    
    echo "\n#########################################################################################";
    echo "\n Migration tool for Nextcloud S3 back to local version 0.21 alpha\n";
    echo "\n special rescue version for edwinosky...";
    
    // Note: Preferably use absolute path without trailing directory separators
    $PATH_BASE      = '/tmp'; // Path to the base of the main Nextcloud directory
    
    $PATH_DATA      = $PATH_BASE.'/data'; // Path of the new Nextcloud data directory
    $PATH_DATA_BKP  = $PATH_BASE.'/data.bkp'; // Path of a previous migration.. to speed things up.. (manually move a previous migration here!!)
    
    $NON_EMPTY_TARGET_OK = 1;
    
    $PATH_DATA_LOCAL_EXISTS_OK = 1; //default 0 !! Only set to 1 if you're sure..
    
    $CONFIG = array (
    // MySql login info
      'dbname'        => 'dbname',
      'dbhost'        => 'dbhost',
      'dbuser'        => 'dbuser',
      'dbpassword'    => 'dbpassword',
      'mysql.utf8mb4' => true,  
    // S3 login info
      'objectstore' => array (
        'arguments' => array (
          'bucket'   => 'bucket',
          'key'      => 'key',
          'secret'   => 'secret',
          'hostname' => 'hostname',
          'region'   => 'region',
        ),
      ),
    ); 
    
    echo "\n\n#########################################################################################";
    echo "\nSetting up S3 migration to local...\n";
    
    // Autoload
    require_once(dirname(__FILE__).'/vendor/autoload.php');
    
    echo "\nconnect to sql-database...";
    // Database setup
    $mysqli = new mysqli($CONFIG['dbhost'], $CONFIG['dbuser'], $CONFIG['dbpassword'], $CONFIG['dbname']);
    if ($CONFIG['mysql.utf8mb4']) {
      $mysqli->set_charset('utf8mb4');
    }
    
    $OBJECT_STORE_ID = 0;
    if ($result = $mysqli->query("SELECT * FROM `oc_storages` WHERE `id` LIKE 'object::store:%'")) {
      if ($result->num_rows>1) {
        echo "\nMultiple 'object::store:' clean this up, it's an accident waiting to happen!!\n";
        die;
      }
      else if ($result->num_rows == 0) {
        echo "\nNo 'object::store:' No S3 storage defined!?\n";
        die;
      }
      else {
        $row = $result->fetch_assoc();
        $OBJECT_STORE_ID = $row['numeric_id']; // for creative rename command..
      }
    }
    
    echo "\nconnect to S3...";
    $s3 = new S3Client([
        'version' => 'latest',
        'endpoint' => 'https://'.$CONFIG['objectstore']['arguments']['bucket'].'.'.$CONFIG['objectstore']['arguments']['hostname'],
        'bucket_endpoint' => true,
        'region'  => $CONFIG['objectstore']['arguments']['region'],
        'credentials' => [
            'key' => $CONFIG['objectstore']['arguments']['key'],
            'secret' => $CONFIG['objectstore']['arguments']['secret'],
        ],
    ]);
    
    // Check that new Nextcloud data directory is empty
    if (count(scandir($PATH_DATA)) != 2) {
      echo "\nThe new Nextcloud data directory is not empty..";
      if (!$NON_EMPTY_TARGET_OK) {
        echo " nAborting script\n";
        die;
      } else {
        echo "WARNING: deleted files since previous copy are NOT removed! (take a look at the option '\$PATH_DATA_BKP')\n";
      }
    }
    
    echo "\n#########################################################################################";
    echo "\nSetting everything up finished ##########################################################\n";
    
    echo "\nCreating folder structure started... ";
    
    if ($result = $mysqli->query("SELECT st.id, fc.fileid, fc.path, fc.storage_mtime FROM oc_filecache as fc, oc_storages as st, oc_mimetypes as mt WHERE st.numeric_id = fc.storage AND st.id LIKE 'object::%' AND fc.mimetype = mt.id AND mt.mimetype = 'httpd/unix-directory'")) {
      
      // Init progress
      $complete = $result->num_rows;
      $prev     = '';
      $current  = 0;
      
      while ($row = $result->fetch_assoc()) {
        $current++;
        try {
          // Determine correct path
          if (substr($row['id'], 0, 13) != 'object::user:') {
            $path = $PATH_DATA . DIRECTORY_SEPARATOR . $row['path'];
          } else {
            $path = $PATH_DATA . DIRECTORY_SEPARATOR . substr($row['id'], 13) . DIRECTORY_SEPARATOR . $row['path'];
          }
          // Create folder (if it doesn't already exist)
          if (!file_exists($path)) {
            mkdir($path, 0777, true);
          }
          #echo "\n".$path."\t";
          touch($path, $row['storage_mtime']);
        } catch (Exception $e) {
          echo "    Failed to create: ".$row['path']." (".$e->getMessage().")\n";
          $flag = false;
        }
        // Update progress
        $new = floor($current/$complete*100).'%';
        if ($prev != $new ) {
          echo str_repeat(chr(8) , strlen($prev) );
          $prev = $current+1 >= $complete ? ' DONE ' : $new;
          echo $prev;
        }
      }
      $result->free_result();
    }
    
    echo "\nCreating folder structure finished\n";
    
    
    echo "Copying files started... ";
    
    $error_copy = '';
    
    if ($result = $mysqli->query("SELECT st.id, fc.fileid, fc.path, fc.storage_mtime FROM oc_filecache as fc,".
                                 " oc_storages as st,".
                                 " oc_mimetypes as mt".
                                 " WHERE st.numeric_id = fc.storage AND st.id LIKE 'object::%' AND fc.mimetype = mt.id AND mt.mimetype != 'httpd/unix-directory'".
                                 " ORDER BY st.id ASC")) {
    
      // Init progress
      $complete = $result->num_rows;
      $current  = 0;
      $prev     = '';
    
      while ($row = $result->fetch_assoc()) {
        $current++;
        try {
          // Determine correct path
          if (substr($row['id'], 0, 13) != 'object::user:') {
            $path = $PATH_DATA . DIRECTORY_SEPARATOR . $row['path'];
          } else {
            $path = $PATH_DATA . DIRECTORY_SEPARATOR . substr($row['id'], 13) . DIRECTORY_SEPARATOR . $row['path'];
          }
          $user = substr($path, strlen($PATH_DATA. DIRECTORY_SEPARATOR));
          $user = substr($user,0,strpos($user,DIRECTORY_SEPARATOR));
    
          #echo "\n".$path."\t".$row['storage_mtime'];
          $copy = 1;
          if(file_exists($path) && is_file($path)){
            if ($row['storage_mtime'] > filemtime($path) ) {
              unlink($path);
            }
            else {
              $copy = 0;
              #echo '.'; // uncomment to see progress
            }
          }
          if ($copy) {
            $path_bkp = str_replace($PATH_DATA,
                                    $PATH_DATA_BKP,
                                    $path);
            if (file_exists($path_bkp) && is_file($path_bkp)
             && $row['storage_mtime'] == filemtime($path_bkp) ) {
              if (rename($path_bkp,
                         $path) ) {
                $copy = 0;
              } else {
                echo "\nmove failed!?\n";
                exit;
              }
              #echo ':';
            }
          }
          if ($copy) {
            // Download file from S3
            $s3->getObject(array(
              'Bucket' => $CONFIG['objectstore']['arguments']['bucket'],
              'Key'    => 'urn:oid:'.$row['fileid'],
              'SaveAs' => $path,
            ));
            // Also set modification time
            touch($path, $row['storage_mtime']);
            #echo '!'; // uncomment to see progress
          }
          #echo ''.$copy."\n";if ($copy) { exit;} 
        } catch (Exception $e) {
          if(file_exists($path) && is_file($path) ){
            unlink($path);
          }
          echo "\n#########################################################################################";
          echo "\nFailed to transfer: $row[fileid] (".$e->getMessage().")\n";
          echo "\ntarget: ".$path."\n";
          echo "datadump of database record:\n";
          print_r($row);
          $error_copy.= $path."\n";
          $prev = '';
          #exit;
        }
        // Update progress
        $new = sprintf('%.2f',$current/$complete*100).'% (now at user '.$user.')';
        if ($prev != $new ) {
          echo str_repeat(chr(8) , strlen($prev) );
          $prev = $current+1 >= $complete ? ' DONE ' : $new;
          echo $prev;
        }
      }
      $result->free_result();
    }
    echo "\n";
    #exit; ###################################################################################
    
    
    if (!empty($error_copy)) {
      echo "\n#########################################################################################";
      $error_count = substr_count($error_copy,"\n");
      echo "\nCopying of ".$error_count." files failed:\n".$error_copy."\n\n";
    }
    
    echo "\nCopying files finished";
    
    echo "\n\ndone..\n";
    
    #########################################################################################
    function recursive_copy($src,$dst) {
      $dir = opendir($src);
      @mkdir($dst);
      while( $file = readdir($dir) ) {
        if ( $file != '.'
         &&  $file != '..' ) {
          if ( is_dir($src . DIRECTORY_SEPARATOR . $file) ) {
            recursive_copy($src . DIRECTORY_SEPARATOR . $file,
                           $dst . DIRECTORY_SEPARATOR . $file);
          } else {
    
            $copy = 1;
            if(file_exists($dst . DIRECTORY_SEPARATOR . $file)){
              if (filemtime($src . DIRECTORY_SEPARATOR . $file) > filemtime($dst . DIRECTORY_SEPARATOR . $file) ) {
                unlink($dst . DIRECTORY_SEPARATOR . $file);
              }
              else { $copy = 0; }
            }
            if ($copy) {
              copy($src . DIRECTORY_SEPARATOR . $file,
                   $dst . DIRECTORY_SEPARATOR . $file);
            }
    
          }
        }
      }
      closedir($dir);
    }
    

    Lett me know how it went..

  18. mrAceT commented on Oct 10, 2022

    @mrAceT

    (no) success?

  19. edwinosky commented on Oct 10, 2022

    @edwinosky
    Author

    (no) success?

    no my friend, i tell you what i am trying to do today, i am using your script to see if data access, create a new install using primary s3, mount that new install to a folder on my server using webdav, now i am seeing if with your script it is possible to recover the data and store it in that new installation, I thought I would write here if it worked for me

  20. edwinosky commented on Oct 10, 2022

    @edwinosky
    Author

    I get this error when executing your script, it seems that it detects the wrong key to connect to S3 R2, the detail is that I already verified my keys, in fact I am using the same key and secret in the new installation and it works fine
    image

  21. mrAceT commented on Oct 10, 2022

    @mrAceT

    The script should continue.. it means that number 482060 does exist in your database, but not in your S3 storage.

    It is very obvious something went horribly wrong.. what that was, I can not tell you..

    But did you cancel the script or did you let it continue?
    If you canceled it, let it go.. it's restore all it can (combining all that is possible combining your S3 and your tables..)
    When you are (more or less) lucky you only have to manually figure out a few of the errors..

    If it canceled by itself.. show me more..

  22. edwinosky commented on Oct 10, 2022

    @edwinosky
    Author

    the script is running, it has been running for more than an hour, the percentage is slowly increasing, I am also monitoring the storage and it does not increase, that is, no information is being downloaded from the s3 storage, I suppose that the script is currently consulting the thousands of indices that I have in my database, I will calmly wait the hours that are necessary

    image

  23. mrAceT commented on Oct 10, 2022

    @mrAceT

    Are you using S3 via WebDav to use S3 as a "mounted folder"?

    If so, I have tried that.. with various ways of connecting.. I'dd advise against it for "life usage".. I got it working, but it was (beyond) slow.. If it's for restoring your data because of lack of disk space I'dd expect you will need to be extremely patient with that amount of data

    PS: maybe change sprintf('%.2f' into sprintf('%.3f' to be sure it didn't die off..

    PS2: if you have set NON_EMPTY_TARGET_OK to '1' you can abort and restart it, the script will skip the files it already got!

  24. edwinosky commented on Oct 10, 2022

    @edwinosky
    Author

    I was using webdav mounted in a folder but it was extremely slow, so I canceled that process and I'm doing it with a normal system folder and of course it goes faster

  25. szaimen commented on Jan 23, 2023

    @szaimen
    Contributor

    Hi, please update to 24.0.9 or better 25.0.3 and report back if it fixes the issue. Thank you!

    My goal is to add a label like e.g. 25-feedback to this ticket of an up-to-date major Nextcloud version where the bug could be reproduced. However this is not going to work without your help. So thanks for all your effort!

    If you don't manage to reproduce the issue in time and the issue gets closed but you can reproduce the issue afterwards, feel free to create a new bug report with up-to-date information by following this link: https://github.com/nextcloud/server/issues/new?assignees=&labels=bug%2C0.+Needs+triage&template=BUG_REPORT.yml&title=%5BBug%5D%3A+

  26. edwinosky commented on Feb 28, 2023

    @edwinosky
    Author

    Hi, please update to 24.0.9 or better 25.0.3 and report back if it fixes the issue. Thank you!

    My goal is to add a label like e.g. 25-feedback to this ticket of an up-to-date major Nextcloud version where the bug could be reproduced. However this is not going to work without your help. So thanks for all your effort!

    If you don't manage to reproduce the issue in time and the issue gets closed but you can reproduce the issue afterwards, feel free to create a new bug report with up-to-date information by following this link: https://github.com/nextcloud/server/issues/new?assignees=&labels=bug%2C0.+Needs+triage&template=BUG_REPORT.yml&title=%5BBug%5D%3A+

    no friend, in the end I ended up losing almost 1TB of files that I had in cloudflare R2 and I could not recover them in any way, unfortunately I did not have them backed up elsewhere, I tried to do everything to recover them, using clean installations and nothing worked for me, anyway In fact, I had to delete the bucket where you had that data because clouflare was charging me and my clients did not have access to the information, now I am using an independent company to take care of storing my data and redid my clients to their links, I will close this topic thanks for the help anyway

  27. tomcatcw1980 commented on Feb 12, 2024

    @tomcatcw1980

    Hello MrAceT,

    first of all, thank you very much for your script. I would also like to reduce the complexity of my NC installation. I have therefore also tried to use your script to switch from S3 to Local. Unfortunately I have not (yet) been successful as the script always aborts. I get similar inconsistency messages as @edwinosky but let the script run until it aborts. However, I cannot see where it breaks off.

    Your script copies all the data from S3 to local. But since the script then aborts, it probably does not update the DB entries to the end or can also run through all other necessary points. Because all the shares no longer exist as soon as I dial into Nextcloud.

    Perhaps I have configured something incorrectly. I still have the following questions about your script that are not quite clear to me:

    1. Who is the clouduser? www-data is probably not, because with sudo www-data I get the message that www-data is logically not sudoer. That's why I just left it at root.
    2. What is meant by this variable? $PATH_BASE = ''; // Path to the base of the main Nextcloud directory. What has to go in there? or I have left it empty, otherwise the path is not correct and the script will not start.
    3. What is the difference to this variable? $PATH_NEXTCLOUD = $PATH_BASE.'/var/www/nextcloud'; // Path of the public Nextcloud directory
    4. Is it intended in your script that it retains the shares etc.?

    Thanks in advance for your answer.

    Best regards
    Christian

    PS: I just got this error message. It copied all data, then asked to continue:

    [...]
    /nc_data/appdata_ocoyq3be73jp/css/terms_of_service/6aaf-32d3-overlay.css.deps
    /nc_data/appdata_ocoyq3be73jp/css/theming/d71e-32d3-settings-admin.css.gzip

    Continue?Y

    Copying files finished
    #########################################################################################
    Modifying database started...
    PHP Fatal error: Uncaught mysqli_sql_exception: MySQL server has gone away in /var/www/nextcloud-s3-to-disk-migration/s3tolocal.php:367
    Stack trace:
    #0 /var/www/nextcloud-s3-to-disk-migration/s3tolocal.php(367): mysqli->query()
    #1 {main}
    thrown in /var/www/nextcloud-s3-to-disk-migration/s3tolocal.php on line 367

  28. mrAceT commented on Feb 12, 2024

    @mrAceT

    no friend, in the end I ended up losing almost 1TB of files that I had in cloudflare R2 and I could not recover them in any way, unfortunately I did not have them backed up elsewhere, I tried to do everything to recover them, using clean installations and nothing worked for me, anyway In fact, I had to delete the bucket where you had that data because clouflare was charging me and my clients did not have access to the information, now I am using an independent company to take care of storing my data and redid my clients to their links, I will close this topic thanks for the help anyway

    Yikes.. I am guessing that the data lost was regrettable but not a disaster? (I think I would have been able to rescue that data).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagebugneeds info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions