diff --git a/index.mjs b/index.mjs index 5571394..f58694d 100644 --- a/index.mjs +++ b/index.mjs @@ -191,7 +191,7 @@ AWS_REGION=${region}`; process.exit(1); } - execSync("pnpm install && pnpm start"); + // execSync("pnpm install && pnpm start"); }); program @@ -342,4 +342,25 @@ program } }); +program + .command("run") + .description("Run the backup process with cron scheduling") + .option("--cron ", "Cron schedule (default is once per day)") + .action((cmd) => { + // Check if .env file exists + if (!fs.existsSync(".env")) { + console.log(chalk.red("Environment variables file not found!")); + console.log(chalk.red("Please run the install command first!")); + process.exit(1); + } + const cronSchedule = cmd.cron || "0 0 * * *"; // Default: once per day + + execSync(`pm2 start run-ts.sh --name dbbackup --cron "${cronSchedule}"`); + execSync("pm2 save"); + + console.log( + chalk.green(`Cron job scheduled with expression: ${cronSchedule}`) + ); + }); + program.parse(process.argv); diff --git a/run-ts.sh b/run-ts.sh new file mode 100644 index 0000000..50cd41d --- /dev/null +++ b/run-ts.sh @@ -0,0 +1 @@ +ts-node -T src/index.ts