Skip to content

Instantly share code, notes, and snippets.

@carchrae
Last active November 12, 2022 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carchrae/c10bff1d588d1630ee4999b3a261ef2a to your computer and use it in GitHub Desktop.
Save carchrae/c10bff1d588d1630ee4999b3a261ef2a to your computer and use it in GitHub Desktop.
/**
steps: (for ubuntu. most shells should be similar)
1) install heroku cli (eg, `npm i -g heroku`)
2) log in (`heroku login`)
3) list apps: `heroku apps > apps.txt`
4) run this script: `node heroku-export.js | bash`
you may want to run step 4 and verify the commands before piping it into bash
*/
const fs = require('fs');
// filter the comment lines, and get app name
const apps = fs
.readFileSync('./apps.txt')
.toString()
.split('\n')
.filter(s => s && !s.startsWith('==='))
.map(s => s.split(' ')[0]);
// git clone of each app
for (const app of apps){
console.log(`heroku git:clone -a ${app}`);
}
// get config vars, addons, and perform postgres database dump
for (const app of apps) {
console.log(`cd ${app}`);
console.log(`heroku pg:backups:capture && heroku pg:backups:download`);
console.log(`heroku addons > addons.txt`);
console.log(`heroku config > config.txt`);
console.log('cat addons.txt; cat config.txt');
console.log(`test -f latest.dump && pg_restore latest.dump -f - > latest.sql`);
console.log(`cd ..`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment