-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zachary Rogers
committed
Oct 17, 2024
1 parent
ba20bf9
commit 7ca9a21
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |