Skip to content

Commit

Permalink
10391: WIP create script for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Rogers committed Oct 17, 2024
1 parent ba20bf9 commit 7ca9a21
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions restoreDbFromTarget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { SSMClient } from '@aws-sdk/client-ssm';
import { execSync } from 'child_process';

async function main() {
// const ssmClient = new SSMClient({ credentials: {}, region: 'us-east-1' });
const sourceDbname = process.env.SOURCE_DB_NAME;
const sourceHost = process.env.SOURCE_HOST;
const sourcePassword = process.env.SOURCE_PASSWORD;
const sourcePort = process.env.SOURCE_PORT;
const sourceUsername = process.env.SOURCE_USERNAME;
// const targetDbname = process.env.TARGET_DB_NAME;
// const targetHost = process.env.TARGET_HOST;
// const targetPassword = process.env.TARGET_PASSWORD;
// const targetPort = process.env.TARGET_PORT;
// const targetUsername = process.env.TARGET_USERNAME;

if (
!sourceDbname ||
!sourceHost ||
!sourcePassword ||
!sourcePort ||
!sourceUsername
// !targetDbname ||
// !targetHost ||
// !targetPassword ||
// !targetPort ||
// !targetUsername
) {
throw new Error('Missing environment variables');
}

const pgDumpOutput = execSync(
`PGPASSWORD="${sourcePassword}" pg_dump --host=${sourceHost} --username=${sourceUsername} --port=${sourcePort} --dbname=${sourceDbname} --file=db_dump.dump --format=c --verbose`,
{ encoding: 'utf-8' },
);
console.log(pgDumpOutput);
}
void main();

type DatabaseInfo = {
password: string;
host: string;
username: string;
port: string;
dbname: string;
};

0 comments on commit 7ca9a21

Please sign in to comment.