Skip to content

Migrate script to update home storage ids #6493

Closed

Description

@PVince81

Write a "migration" or "fix db" script that admins can run from the command line.

When users migrated from very old ownCloud versions to OC 6, they might find themselves with a mix of different storage id formats like here: #6463 (comment) which can cause unpredictable bugs (like #6463)

The purpose of the script is to convert all home storages to use the "home::$username" format.

BUT there might be some situations where admins might have tinkered with the storage ids to move user's mount points to different places, for example: "local:://home/user1" for user1 "local::/someotherdir/user2" where the subdir is not a subdir of the data folder. (which might be a reason why @DeepDiver1975 was against having this in the automatic migration back then when we introduced the home storages)

The script must perform a test to check whether all home storages can be converted. If one or more cannot, the script will abort and show a warning.

If all can be migrated, the migration will be done.

@karlitschek @icewind1991 @DeepDiver1975 @schiesbn

Activity

  1. githubrsys commented on Dec 18, 2013

    @githubrsys

    #6464 is a regression of #6463

  2. karlitschek commented on Dec 18, 2013

    @karlitschek
    Contributor

    Yes. We need this. The script itself already exists we "only" have to add the logic.
    We should do the same to fix this: #6481

  3. PVince81 commented on Dec 20, 2013

    @PVince81
    ContributorAuthor

    @icewind1991 can you take care of this as you might have more knowledge about the different storage formats over the OC versions.

    This is important because some parts of the code (quota) rely on the home storage being identified correctly, which it can't be with older storage formats.

  4. PVince81 commented on Mar 4, 2014

    @PVince81
    ContributorAuthor

    So far I've seen at least 3-4 accounts of such issues because people moved their data folders but the oc_storages still used the old format that contains the hard-coded path.

    Added "bug" tag as this fixes a real issue and isn't just a "nice to have".

  5. childnode commented on Mar 4, 2014

    @childnode

    as @PVince81 pointed out in #7203 , possibly there is a core problem with the oc_filecache that doesn't upg/date to the new home:: mounts?

    The numeric_id is used in the oc_filecache table in the storage column.
    I checked the oc_share table and it doesn't seem to use it, it only relies on the unique file id which maps to the fileid column in oc_filecache.

    nevertheless: what is strange to me: new home:: mount-points / storages are not created for all users but only for the one who added files after migration to OC 6??

    This migrate script then has to fix all these dups too.

    my oc_storage table looks like

    1|local::/srv/owncloud/data/user1/
    2|local::/srv/owncloud/data/user2/
    3|local::/srv/owncloud/data/
    4|google::1/FOOOOOOOBAR1
    5|local::/srv/owncloud/data/user3/
    6|local::/srv/owncloud/data/user4/
    7|google::1/FOOOOOOOBAR2
    8|home::user1
    9|home::user5
    

    which indeed, leads to duplicated entries in the oc_filecache table

    sqlite3 owncloud.db "select * from oc_filecache where storage in (1,3,8) and path = 'files/myFile.txt'"
    
    1999|1|files/myFile.txt|1966|myFile.txt|18|4|1312835775|0|5148d798036d0|3683884cafaf1bb3f205b0ff47abb102|0|49828|0
    14621|8|files/myFile.txt|14596|myFile.txt|12|4|1312835775|0|53049c335dd3e|3683884cafaf1bb3f205b0ff47abb102|1312835775|49828|0
    

    ;(

  6. PVince81 commented on Mar 4, 2014

    @PVince81
    ContributorAuthor

    @childnode the issue is not in oc_filecache but in oc_storages as your post above showed.

    Let me clarify:

    For OC version < 5.0.13, all storages were based on the id format local::/path/to/data/username.
    Starting with OC 5.0.14 and up, including OC 6, a new id format home::username was introduced to fix the "moving the data folder" issue.

    Trouble is that we chose to not automatically convert the ids as it might break some installs, potentially ones where admins manually changed the paths in the DB (CC @DeepDiver1975 can you comment on this ?)

    So this ticket is about writing a command that can be run manually to fix this case when you know that you didn't mess up with the DB manually.

    This means that:

    1. Users that logged in before the migration still have the old storage id format (the ones that used OC at the time it was version <= 5.0.12)
    2. Users that have logged in after the migration (OC >= 5.0.13) will get the new storage id format.

    Hope this helps.

  7. PVince81 commented on Mar 4, 2014

    @PVince81
    ContributorAuthor

    The thing is, as long as you don't move the data folder, the old id format still works.

    Problem is only when you have legacy storage ids AND you move the data folder 😦

  8. childnode commented on Mar 4, 2014

    @childnode

    @PVince81

    Problem is only when you have legacy storage ids AND you move the data folder

    But there is also no way to force this update (via frontend) BEVORE moving, right?

    Your explanation also doesn't make it comprehensible to me to understand why user1 is there twice?

  9. PVince81 commented on Mar 4, 2014

    @PVince81
    ContributorAuthor

    @childnode good point.

    Sorry, I didn't see that user1 was redefined. It is not supposed to.
    Based on your oc_storages the expected behavior is to reuse the local::/srv/owncloud/data/user1/ and not create a new one, given that your data path is still "/srv/owncloud/data/".

    Currently this update can't be forced, there is no code that can do this now, hence this ticket to provide one.

    @DeepDiver1975 @icewind1991 @karlitschek I took some time to look through the PRs and tickets and can't find in which one we discussed the reason against providing an automatic upgrade path for this.
    Can you remind me why we can't automatically replace the "local::" storage with "home::" during migration for all paths that match the data folder ?

  10. DeepDiver1975 commented on Mar 4, 2014

    @DeepDiver1975
    Contributor

    Can you remind me why we can't automatically replace the "local::" storage with "home::" during migration for all paths that match the data folder ?

    My initial throughts have been that "local::" is not only used to mount the user's home folder but also other local folders can be mounted - this might cause fuxxups

  11. PVince81 commented on Mar 4, 2014

    @PVince81
    ContributorAuthor

    One way I thought this could be done is detecting whether the "local::" id is in the format "local::" + datadir + "/username/" in which case it would be migrated where datadir is the currently configured data dir and username any user name.

    If it uses any other format it should be left alone.
    That might happen when using the "Local" external storage option, in which case the format is "local::" + localPath.

    I can't think of any case where an admin would manage to somehow match the same format as for the local home storage.

  12. PVince81 commented on Mar 4, 2014

    @PVince81
    ContributorAuthor

    See attached PR with a work in progress repair script.

  13. DeepDiver1975 commented on Mar 4, 2014

    @DeepDiver1975
    Contributor

    If it uses any other format it should be left alone.
    That might happen when using the "Local" external storage option, in which case the format is "local::" + localPath.

    crazy idea: setup a local mount to another user's datadir? 😉

  14. PVince81 commented on Mar 5, 2014

    @PVince81
    ContributorAuthor

    @DeepDiver1975 do we need a repair script for crazy admins as well ? 😉

    It should be possible to catch that case, but I need to change the way of the user id is extracted.
    Because that crazy local mount scenario would have an id like "local::" + dataDir + userId + "/files/subdir". So the idea would be to make sure that the extracted user id doesn't contain slashes.

  15. karlitschek commented on Mar 5, 2014

    @karlitschek
    Contributor

    great initiative @PVince81 Makes sense 👍

  16. PVince81 commented on Mar 5, 2014

    @PVince81
    ContributorAuthor

    Ouch, once again posted in the issue instead of the PR.

  17. self-assigned this
    on Mar 6, 2014
  18. PVince81 commented on Mar 24, 2014

    @PVince81
    ContributorAuthor

    Yet another user affected by this issue: #7774
    When the situation where "home::" and "local::" both exist for the same user, it seems to cause syncing issues, files would be redownloaded multiple times.
    I haven't verified this yet, need to test it.

  19. flop25 commented on Jun 4, 2014

    @flop25

    Hello an sry to disturb you here, but is that issue solved? Because I just find I was stuck on 5.0.10 due to a wonderfull bug: should I start from a new install then move the backuped folders for all users, or can I really safely upgrade?

  20. PVince81 commented on Jun 4, 2014

    @PVince81
    ContributorAuthor

    The repair script isn't ready yet due to tricky situations that cannot be handled.

    You might want to upgrade to 5.0.16 first and then make sure that the oc_storages table doesn't contain any hard-coded data directories any more. If it does, you could change them manually to the home:: format before further upgrade.

  21. added this to the milestone on Jun 24, 2014
  22. locked as resolved and limited conversation to collaborators on Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions