Export all share for migration

Hello,

I search an idea for exporting share from a Nextcloud to import them in another Nextcloud.

For now I have a sql request like that to export share initialised by an admin user

select share_type,share_with,password,uid_owner,uid_initiator,item_type,item_source,item_target,file_source,file_target,permissions,accepted,expiration,token,note,hide_download,password_expiration_time  from nextcloud.oc_share where uid_initiator='admin'

Does someone have a better idea ? A script to do that ?

Best regards

Usually you want to migrate not only the share information but all server data as well:

https://docs.nextcloud.com/server/latest/admin_manual/maintenance/migrating.html#migrating-to-a-different-server

If you really only want to migrate share URLs I think your query will export everybody shares once you remove where uid_initiator='admin' from the SQL statement… You can use Configurable Share Links app on the new instance to re-create shares using old links.

@wwe I have to consolidate two Nextcloud in a new one, so I have to export all share for all users in the two nextcloud and change user mapping (bad ad mapping) and integrate them in a new installation.

With occ i can export groupfolders list but not classic share

interesting challenge! if you are looking for internal shares as well I think it will be pretty hard to migrate them. may be the easier approach would be to migrate the data of individual users to the new instance using user migration app and then setup all required internal shares from scratch. maybe worth to look through user-migration-app topics - maybe you can find useful hints.

UPDATE: I’m wondering you are aware of official occ sharing:list command which lists all the shares in the system? (likely the same you get with a SQL query above)

    {
        "id": "140",
        "file_id": 4305614,
        "owner": "user1",
        "initiator": "user1",
        "time": "2023-05-04T14:36:26+00:00",
        "permissions": 17,
        "path": "\/Fotos\/cat",
        "name": "cat",
        "is_directory": true,
        "type": "email",
        "recipient": "share.recipient@some.domain",
        "token": "M76d6HnMjQsdfasdf"
    },

@wwe I haven’t got this command sharing:list

 php occ sharing

                                       
  Command "sharing" is not defined.    
                                       
  Did you mean one of these?           
      sharing:cleanup-remote-storages  
      sharing:expiration-notification  

I have to admit the hint was misleading :speak_no_evil:
the command comes from the app Share listing + Share listing Github ! not official but worth installing.

Ok very good I didn’t know this app. So It’s interesting for exporting share but after i can’t recreate them on another nextcloud unless there is an application like sharing:import ?

I don’t think there is general way to import/re-create shares on another system - too many moving parts, user id might change, files and folders have another IDs - mission impossible I would say.

@wwe you know where file and directory id are stored ?

I’m not ware of any official documentation of DB structure. we had pretty comprehensive reverse engineering of the DB in this thread Desktop client 3.4.0 destroys local time stamp and keeps uploading data to server maybe this is the best source I have handy…