I want a one click migration feature where back office users will be presented with a page. When click on a button on that page, the content from one installation will be copied to another installation.
I read that uSync can do that but that requires user to go to developer section of both the installation.
So I am thinking to write a wrapper around uSync which do this job for me. But I am not well aware of uSync and Umbraco and not sure how to start. Any help will be appreciated.
Yeah it's all possible - but isn't everything possible for developers :)
Below is the detail of what you might need to do, but for a "simple" answer it might be worth you looking at uSync.Snapshots code, and
working out if you could just use that to create the snapshot, fire it
over (see below) and run the snapshot on the other side
Firstly to communicate between the sites you are going to need to have some WebApi endpoint (ApiController) on the target site , and a way of making it secure (so shared key / auth).
Once that is done ! You will either need to pass the uSync configs over to the target server via the api, or know that they are getting copied somehow between the source and server folders. so you might for example export the items via usync - zip them up? and send them over the wire to the target server.
Once you have the file(s) on the server you can call the uSync api endpoints to do the importing.
There are "simple" enpoints for performing imports and exports of the whole lot - these are:
but these do everything they find in the folder (so all doctypes, datatypes, content). You might for example only want to import a single doctype then you need to get the uSync Handler for doctypes and ask it to import the single file.
But! things don't have to go to disk at all - you can extract the config you want to push into memory pass it over and then import it from memory using the uSync.Core library (in reality this does all the hard work; all the usync.backoffice library does is mange umbraco events, and things going to and from the disk)
With the core you can - for example - export a content item:
var attempt = uSyncCoreContext.Instance.ContentSerializer.Serialize(item);
this will give you the XElement object in attempt.Item
you then pass this over and at the other end :
var attempt = uSyncCoreContext.Instance.ContentSerializer.Deserialize(node, parentId, force);
(in this instance for content you need to know or find the parentId on the target site, so you know where the content goes.
Content is a two pass sync (because links and things might not be valid the first time the import is processed) - so you also need to call :
With all of this you will also need to consider syncornization, so depending on your setup and the nature of deployment you might be ok just sending a single bit of content or config over to the target server, but if it is missing the doctype/datatypes/templates that make up that config then you are not going to get a successful sync.
So what courier does (i believe) is work out what dependencies there are for any particular item (so for content, you need to find the doctypes, for those doctypes the datatypes, templates and any parent/compositions) bundle them all up and send them over as part of the sync.
Thank you for such detailed answer, Kevin! This really gave me insights of the tool.
I will take a look at Snapshot feature.
A questions is - WIll this uSyncCoreContext and uSyncBackOfficeContext always be available in ApplicationContext? How will I access this? Injecting through something?
The contexts are singletons, so should always available within an umbraco app.
They are not resolvers or anything fancy (yet) so don't need to be injected into the controllers, (this does make unit testing with the current usync difficult)
I just got more detail on my requirement. I have to actually move the content from one Content area (Parent) to another content area(Parent) on the same Umbraco Instance.
I believe the Content edition will not work for me as it updates contents and matches the IDs, so if I export and import back on the same instance, it will update the original content area and not in the second content area.
yeah content edtion won't work for that - because as you say it's internal content id matching .
but
Translation Manager might: ) (stop me here if you want, I after all am always going to think things i wrote will solve problems)
primarily as the name suggests i has been written for translations
but translation manager will copy content around a single umbraco instance, updating links and content as it goes,
There is a Passthrough Provider that does nothing more than push the content from one place to another (its for when one instance has two sites for similar languages (e.g en-US and en-GB sites) - but this means you can 'send to translate' a section of a site and if it's configured this will just push the content from one place to another.
Wrapper around uSync
I want a one click migration feature where back office users will be presented with a page. When click on a button on that page, the content from one installation will be copied to another installation.
I read that uSync can do that but that requires user to go to developer section of both the installation.
So I am thinking to write a wrapper around uSync which do this job for me. But I am not well aware of uSync and Umbraco and not sure how to start. Any help will be appreciated.
Hi
Yeah it's all possible - but isn't everything possible for developers :)
Firstly to communicate between the sites you are going to need to have some WebApi endpoint (ApiController) on the target site , and a way of making it secure (so shared key / auth).
Once that is done ! You will either need to pass the uSync configs over to the target server via the api, or know that they are getting copied somehow between the source and server folders. so you might for example export the items via usync - zip them up? and send them over the wire to the target server.
Once you have the file(s) on the server you can call the uSync api endpoints to do the importing.
There are "simple" enpoints for performing imports and exports of the whole lot - these are:
but these do everything they find in the folder (so all doctypes, datatypes, content). You might for example only want to import a single doctype then you need to get the uSync Handler for doctypes and ask it to import the single file.
You might be best looking at how the uSync chauffeur deliverable does that https://github.com/KevinJump/uSync/blob/v4_master/Jumoo.uSync.Chauffeur/uSyncDeliverable.cs#L175
But! things don't have to go to disk at all - you can extract the config you want to push into memory pass it over and then import it from memory using the uSync.Core library (in reality this does all the hard work; all the usync.backoffice library does is mange umbraco events, and things going to and from the disk)
With the core you can - for example - export a content item:
this will give you the XElement object in
attempt.Item
you then pass this over and at the other end :
(in this instance for content you need to know or find the parentId on the target site, so you know where the content goes.
Content is a two pass sync (because links and things might not be valid the first time the import is processed) - so you also need to call :
With all of this you will also need to consider syncornization, so depending on your setup and the nature of deployment you might be ok just sending a single bit of content or config over to the target server, but if it is missing the doctype/datatypes/templates that make up that config then you are not going to get a successful sync.
So what courier does (i believe) is work out what dependencies there are for any particular item (so for content, you need to find the doctypes, for those doctypes the datatypes, templates and any parent/compositions) bundle them all up and send them over as part of the sync.
Thank you for such detailed answer, Kevin! This really gave me insights of the tool. I will take a look at Snapshot feature. A questions is - WIll this uSyncCoreContext and uSyncBackOfficeContext always be available in ApplicationContext? How will I access this? Injecting through something?
Hi
The contexts are singletons, so should always available within an umbraco app.
They are not resolvers or anything fancy (yet) so don't need to be injected into the controllers, (this does make unit testing with the current usync difficult)
Thanks Kevin!
I just got more detail on my requirement. I have to actually move the content from one Content area (Parent) to another content area(Parent) on the same Umbraco Instance.
I believe the Content edition will not work for me as it updates contents and matches the IDs, so if I export and import back on the same instance, it will update the original content area and not in the second content area.
Hi
yeah content edtion won't work for that - because as you say it's internal content id matching .
but
Translation Manager might: ) (stop me here if you want, I after all am always going to think things i wrote will solve problems)
primarily as the name suggests i has been written for translations but translation manager will copy content around a single umbraco instance, updating links and content as it goes,
There is a Passthrough Provider that does nothing more than push the content from one place to another (its for when one instance has two sites for similar languages (e.g en-US and en-GB sites) - but this means you can 'send to translate' a section of a site and if it's configured this will just push the content from one place to another.
So I got more things to research on but it will definitely help me gain more understanding of Umbraco system.
Many thanks for all this help, Kevin. And I will let you know how it goes. :)
is working on a reply...