Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
contentful-space-sync
Advanced tools
This tool allows you to perform a one way synchronization of published content from one Contentful space to another.
The tool makes use of Contentful's Synchronization API which means that if you run the tool in the future with the provided token, you will only synchronize new and updated Entries and Assets, as well as remove any that have been deleted.
--content-model-only
optionWhile this is possible, we do not advise that you use this tool for backups for the following reasons:
Each time you run the tool it stores a synchronization token so only new Entries and Assets get copied, and so that deleted items can also be deleted on the destination space. See the Synchronization documentation for more details.
Content Types will always be updated as they are not retrieved by the synchronization API, and Content Types which don't exist anymore in the source space will be deleted in the destination space as well.
If you make any manual changes in the destination space, be aware that this tool will overwrite any changes you've made to entities with the same ids as those existent on the source space.
Also, avoid creating new Content Types and Entries in the destination space. This tool is intended to be used with a workflow where you create content on one space and then regularly copy it somewhere else in an automated way.
Check out the releases page.
npm install -g contentful-space-sync
Usage: contentful-space-sync [options]
Options:
--version Show version number
--source-space ID of Space with source data
[string] [required]
--destination-space ID of Space data will be copied to
[string] [required]
--source-delivery-token Delivery API token for source space
[string] [required]
--management-token Management API token for both spaces.
[string]
--source-management-token Management API token for source space, if
different from --management-token.
[string]
--destination-management-token Management API token for destination space if
different from --management-token.
[string]
--pre-publish-delay Delay in milliseconds to account for delay
after creating entities, due to internal
database indexing
[default: 5000]
--sync-token-dir Defines the path for storing sync token files
(default path is the current directory)
[string]
--content-model-only Copies only content types and locales
[boolean]
--skip-content-model Skips content types and locales. Copies only entries and assets
[boolean]
--skip-locales Skips locales. Must be used with --content-model-only.
Copies only content types.
[boolean]
--delivery-host Host for the Delivery API.
[string]
--delivery-port Port for the Delivery API.
[string]
--delivery-insecure If the Delivery API should use http instead of the default https.
[boolean]
--management-host Host for the Management API.
[string]
--management-port Port for the Management API.
[string]
--management-insecure If the Management API should use http instead of the default https.
[boolean]
--proxy-host hostname of the proxy server. [string]
--proxy-port port of the proxy server. [string]
--rate-limit How many request per period of time, default 6 [number]
--rate-limit-period How much time to wait before retry in ms, default 1000 [number]
--config Configuration file with required values
The --management-token
parameter allows you to specify a token which will be used for both spaces. If you get a token from https://www.contentful.com/developers/docs/references/authentication/ and your user account has access to both spaces, this should be enough.
In case you actually need a different management token for any of the spaces, you can use the --source-management-token
and --destination-management-token
options to override it.
Check the example-config.json
file for an example of what a configuration file would look like. If you use the config file, you don't need to specify the other options for tokens and space ids.
contentful-space-sync \
--source-space sourceSpaceId \
--source-delivery-token sourceSpaceDeliveryToken \
--destination-space destinationSpaceId \
--destination-management-token destinationSpaceManagementToken
or
contentful-space-sync --config example-config.json
You can create your own config file based on the example-config.json
file.
While this tool is mostly intended to be used as a command line tool, it can also be used as a Node library:
var spaceSync = require('contentful-space-sync')
spaceSync(options)
.then((output) => {
console.log('sync token', output.nextSyncToken)
})
.catch((err) => {
console.log('oh no! errors occurred!', err)
})
The options object can contain any of the CLI options but written with a camelCase pattern instead, and no dashes. So --source-space
would become sourceSpace
.
Apart from those options, there are two additional ones that can be passed to it:
errorLogFile
- File to where any errors will be written.syncTokenFile
- File to where the sync token will be written.The method returns a promise, where, if successful, you'll have an object which contains the nextSyncToken
(only thing there at the moment). If not successful, it will contain an object with errors.
You can look at bin/space-sync
to check how the CLI tool uses the library.
This tool uses the Contentful Synchronization endpoint to keep content synchronized over repeated runs of the script.
Behind the scenes, when you use the sync endpoint, apart from the content it also returns a sync token in its response. The sync token encodes information about the last synchronized content, so that when you request a new synchronization, you can supply it this content and you'll only get new and updated content, as well a list of what content has been deleted.
When you run this tool, it will create a file in the current directory named contentful-space-sync-token-sourceSpaceId-destinationSpaceId
. If you run the tool again in the directory where this file resides, with the same source and destination space IDs, it will read the token from the file. If you have a token from somewhere else you can just create the file manually.
If any errors occur during synchronization, the tool will also create a time stamped log file (contentful-space-sync-timestamp.log
) with a list of any errors which occurred, and links to the entities in the source space which might have problems that need to be fixed.
The most common problem will probably be an UnresolvedLinks
error, which means a published entry A links to another entry B or asset C which has been deleted since publishing of the entry A.
If you come across this problem, you can use contentful-link-cleaner to clean all of those unresolved references.
By using the --content-model-only
option, you can copy only Content Types and Locales. This means you'll get a space with the same content structure, but with no content at all.
This might be useful if you have been trying things out but want to start fresh with your content, or if you have a need to delete fields from your existing Content Types.
By using the --skip-content-model
option, you can copy only Entries and Assets. This assumes you have used this script before with the --content-model-only
option or created the exact same content structure by hand.
Every time you run the script without any of these options, it will attempt to update the content model as well, so on subsequent syncs it might be desirable to use this option to make things a bit faster.
While we used to recommend this tool as a way to do field deletion through a specific workflow, this feature is now available on the Contentful UI.
These options were very problematic and caused more problems than they solved, so they were removed on version 4. You can see more details here and here.
If you think you need these options, we advise you create a new, empty space, and restart the synchronization process from scratch.
If you really really really REALLY need those options and you are aware of how much trouble they can cause, you can always use an older version of the tool.
FAQs
Syncs Contentful spaces
The npm package contentful-space-sync receives a total of 30 weekly downloads. As such, contentful-space-sync popularity was classified as not popular.
We found that contentful-space-sync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.