This file contains hidden or 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
import { SQL, sql } from 'drizzle-orm'; | |
/** | |
* Converts a raw object or array to a jsonb object for postgres | |
* | |
* @export | |
* @template T | |
* @param {(T | T[])} raw | |
* @return {*} {SQL<unknown>} | |
* |
This file contains hidden or 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
#! /bin/bash | |
# declare colors | |
Red=$'\e[1;31m' | |
Green=$'\e[1;32m' | |
Blue=$'\e[1;34m' | |
Yellow=$'\e[1;33m' | |
# exit when any command fails | |
set -e |
This file contains hidden or 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
const { exec } = require('child_process'); | |
const CronJob = require('cron').CronJob; | |
// scheduling the backup job | |
var job = new CronJob('59 23 * * *', | |
function () { | |
console.log('-------Running cron job-------'); | |
backupDatabase(); | |
}, | |
null, | |
true |
This file contains hidden or 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
#!/bin/bash | |
PGPASSWORD=${1} pg_dump -h ${2} -U ${3} -p ${4} -Fc -d ${5} > ${6} |
This file contains hidden or 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
const backupDatabase = () => { | |
// extract credentials from .env | |
const dbName = process.env.DB_NAME; | |
const dbPass = process.env.DB_PASS; | |
const dbHost = process.env.DB_HOST; | |
const dbUser = process.env.DB_USER; | |
const dbPort = process.env.DB_PORT; | |
const format = "backup"; // sql/backup/dump | |
// create a custom backup file name with date info | |
const date = new Date(); |
This file contains hidden or 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
// automated-backups/index.js | |
const dotenv = require('dotenv'); | |
dotenv.config(); | |
const express = require('express'); | |
const app = express(); | |
const { exec } = require('child_process'); | |
// execute node child process(exec) | |
exec(`sh ./backup.sh`, (error, stdout, stderr) => { | |
if (error) { | |
console.error(`exec error: ${error}`); |
This file contains hidden or 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
#!/bin/bash | |
PGPASSWORD=mysupersecret pg_dump -h localhost -U postgres -p 5432 -Fc -d sampledb > | |
/Users/<username>/<path_to_dir>/sample.backup |
This file contains hidden or 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
#!/bin/bash | |
echo "I can run sh scripts" |