Skip to content

Instantly share code, notes, and snippets.

@lloesche
Last active June 3, 2019 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloesche/09b70031f6f815c77fba1bba8efd42ff to your computer and use it in GitHub Desktop.
Save lloesche/09b70031f6f815c77fba1bba8efd42ff to your computer and use it in GitHub Desktop.
Backup/Restore DC/OS Services and Jobs from one cluster to another in a suspended state
CLUSTER_A=olddcos
CLUSTER_B=newdcos
# BACKUP SERVICES
dcos cluster attach $CLUSTER_A
curl -H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/service/marathon/v2/apps | \
jq '.[] | del(.[].version) | del(.[].uri) | del(.[].versionInfo) | del(.[].tasksStaged) | del(.[].tasksRunning) | del(.[].tasksHealthy) | del(.[].tasksUnhealthy) | del(.[].deployments)' > apps.json
for id in $(jq -r '.[] | "\(.id)"' apps.json); do cleanid="${id//\//_}"; jq ".[] | select(.id==\"$id\") | .instances=0" apps.json > service.${cleanid:1}.json; done
# BACKUP JOBS
dcos cluster attach $CLUSTER_A
dcos job list --json > jobs.json
for id in $(jq -r '.[] | "\(.id)"' jobs.json); do cleanid="${id//\//_}"; jq ".[] | select(.id==\"$id\") | del(.historySummary) | del(.activeRuns) | .schedules[].enabled=false" jobs.json > job.${cleanid}.json; done
# RESTORE SERVICES
dcos cluster attach $CLUSTER_B
ls -1 service.*.json | xargs -n 1 dcos marathon app add
# RESTORE JOBS
dcos cluster attach $CLUSTER_B
ls -1 job.*.json | xargs -n 1 dcos job add
# BACKUP AND RESTORE SECRETS
https://github.com/justinrlee/dcos-secrets-backup/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment