all repos — dbee @ b22378184073ce48c49767ed1031a99e1e83166c

Move PostgreSQL backups using S3

libs/psql/shellCmd.js (view raw)

 1const chalk = require("chalk");
 2const exec = require("child_process").exec;
 3
 4const execPsqlCommand = async (command = "", psqlConfig) => {
 5  const { host, port, username, password } = psqlConfig;
 6  let shellCmd = `${command} -h ${host} -p ${port} -U ${username}`;
 7
 8  console.log(chalk.grey(shellCmd));
 9
10  if (password) shellCmd = `PGPASSWORD=${password} ${shellCmd}`;
11
12  return new Promise((resolve, reject) => {
13    exec(shellCmd, (error, stdout) => {
14      if (error) reject(error);
15      else resolve(stdout);
16    });
17  });
18};
19
20module.exports = execPsqlCommand;