Bash script for making periodical back-ups of Contentful entries and assets. Contentful Bash Back-up is compatible with Unix-like operating systems such as Linux or macOS.
Contentful provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
Contentful is registered trademark of Contentful GmbH.
Teemu Tammela
- [email protected]
- www.auralcandy.net
- github.com/teemutammela
- www.linkedin.com/in/teemutammela
- t.me/teemutammela
Contentful Bash Back-up is distributed under GNU General Public License v3.0 and comes with absolutely no warranty. The author assumes no responsibility of data loss or any other unintended side-effect.
- Exports entries and assets as JSON data and compresses them as ZIP-files.
- Option to download asset files (incremental, no duplicates).
- Silent running, all output is printed into export log.
1) Clone repository.
$ git clone https://github.com/teemutammela/contentful-bash-backup.git
2) Install Contentful CLI.
$ npm install -g contentful-cli
3) If you don't already have a management token, create one in the Contentful Web App at Space settings → API keys → Content management tokens.
$ ./run.sh help
$ ./run.sh [-t </PATH/TO/TARGET_DIR>] [-m <MANAGEMENT_TOKEN>] [-s <SPACE_ID>] [-e <ENVIRONMENT_ID>] [-f]
Parameter | Description | Required | Default Value |
---|---|---|---|
-t |
Path to Back-up Target Directory | Yes | - |
-m |
Contentful Management Token | Yes | - |
-s |
Contentful Space ID | Yes | - |
-e |
Contentful Environment ID | No | master |
-f |
Download Asset Files | No | No |
Contentful Bash Back-up is intended to be used in conjunction with cron
. As a general rule of thumb, it's practical to export entries more often than assets, as entries change more frequently. In the following example entries are exported every day at 12:15. Another export operation that also downloads the assets is executed every Sunday at 12:30.
15 12 * * * /bin/sh /path/to/contentful-bash-backup/run.sh -t "/path/to/target_dir/" -m "XYZ123" -s "XYZ123" >/dev/null 2>&1
30 12 0 * 7 /bin/sh /path/to/contentful-bash-backup/run.sh -t "/path/to/target_dir/" -m "XYZ123" -s "XYZ123" -f >/dev/null 2>&1
After the export process is complete, a new back-up file is located at /<TARGET_DIR>/entries/YYYY-MM/entries-YYYY-MM-DD_HH.MM.SS.zip
and the log at /<TARGET_DIR>/logs/YYYY-MM/entries-YYYY-MM-DD_HH.MM.SS.log
.
NOTE! Entries and assets in draft state are not exported.
If the -f
parameter was selected, assets are located in directories /<TARGET_DIR>/downloads.ctfassets.net/
and /<TARGET_DIR>/images.ctfassets.net/
. Please note, that in order to avoid duplicate files, asset directories are not compressed which can consume a fair amount of storage space.
NOTE! Downloading asset files can be a lengthy process and can potentially deplete your bandwidth quota depending on your subscription model. Please refer to Contentful's Fair Use Policy documentation for further details.