Skip to content

Instantly share code, notes, and snippets.

@jpopesculian
Created May 26, 2021 21:44
Show Gist options
  • Save jpopesculian/ca60076389b2baa8e6ca103ea9d2e628 to your computer and use it in GitHub Desktop.
Save jpopesculian/ca60076389b2baa8e6ca103ea9d2e628 to your computer and use it in GitHub Desktop.
Import/Export CPS

To run the export from CPS use bash export and to run the import to CPS use bash import

To configure, you can use the the variables:

  • DATA_DIR: the output/input directory for the exported/imported session files
  • CPS_HOST: the hostname (and optional port) for the running CPS you would like to import/export from
#!/bin/bash
set -ex
data="${DATA_DIR:-./data}"
cps="https://${CPS_HOST:-localhost:6000}"
# get session names
mapfile -t session_names < <(curl -k "$cps/sessions"| jq .data | jq -r 'keys[]')
# create data directory
mkdir -p "$data"
# fetch and store sessions
for session_name in "${session_names[@]}"
do
# get session | remove predecessor | remove access policy | remove doc header
curl -k "$cps/sessions/$session_name" \
| sed '/predecessor:.*$/d' \
| head -n -6 \
| tail -n +2 \
> $data/$session_name.yaml
done
#!/bin/bash
set -ex
data="${DATA_DIR:-./data}"
cps="https://${CPS_HOST:-localhost:6000}"
# post all session files in data directory
for session_file in $data/*.yaml
do
curl -k -X POST --data-binary @"$session_file" "$cps/sessions"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment