https://github.com/azzaky9/cron-job-backup-weekly
Schedule Backup Weekly with Node Js and shell Script
https://github.com/azzaky9/cron-job-backup-weekly
Last synced: 3 months ago
JSON representation
Schedule Backup Weekly with Node Js and shell Script
- Host: GitHub
- URL: https://github.com/azzaky9/cron-job-backup-weekly
- Owner: azzaky9
- Created: 2024-05-04T01:19:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-16T16:44:37.000Z (about 1 year ago)
- Last Synced: 2024-11-29T11:46:05.064Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Cron Job Backup Database MySql Weely
> (You can also using another Sql Database but you need extra configuration)
The purpose of this code is for schedule the backup your data you served with Sql DBMS, this code have low memory usage i'm not use extra library for serving Web Server like ``(Express or Something Else..)`` instead of using the library i prefer doing the same thing
just only using ``http:server`` from ``Node Js`` and for executing the shell script from node js i use ``child_process``.What case fit for this Cron Jobs Worker ?
- Your app served in VPS
- Your app using MySql for DBMS
- Low Library UsageDEFAULT CONFIG
- Day = 'Friday'
- Times = 23:00
- Schedule = 'Weekly'### Shell Script Config
```js
// make your own .env
// Location ./src/backup.jsconst host = process.env.DB_HOST;
const username = process.env.DB_USERNAME;
const password = process.env.DB_PASSWORD;
const dbName = process.env.DB_NAME;
const backupPath = process.env.BACKUP_PATH;
```
### Default Backup Script
```shell
# Location ./src/backup.jsmysqldump -u ${username} -p${password} ${dbName} > ${backupPath}/${date.getFullYear()}-${date.getMonth()}-${date.getDay()}At[${date.getHours()}:${date.getMinutes()}]-backup-${host}.sql
```### Default Executable Cron Jobs.
```js
// Location main.jsnew CronJob(
"* * 23 * * 5", // Make your own configuration
function () {
console.log("============== Cron Fire =============");
executeBackup();
},
"Cron sucessfully execute without problem.",
true,
"America/Los_Angeles"
)
```#### Refference Library
+ [Cron Js](https://github.com/kelektiv/node-cron)
+ [Winston](https://www.npmjs.com/package/winston)
+ [dotenv](https://www.npmjs.com/package/dotenv)#### Technolgy
+ Node Js v20.12.2
+ Package Manager (PNPM) v9.0.6