Registry / database / cron-mysql-backup

cron-mysql-backup

JSON →
library2.0.2jsnpmunverified

A Node.js module to automate MySQL database backups on configurable intervals using cron syntax. Version 2.x uses node-cron and requires SendGrid for email notifications. It automatically purges old backups to manage disk space. The package is tightly coupled to SendGrid (no other email providers) and mysql (mysqldump). Last updated in 2020; no recent activity.

npm install cron-mysql-backup
INSTALL
IMPORT
SIG · CRON-MYSQL-BACKUP
C
cron-mysql-backup
databasejavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const cronMysqlBackup = require('cron-mysql-backup');
import cronMysqlBackup from 'cron-mysql-backup';
This package uses CommonJS and does not support ES module import syntax. It exports a single function.

Initializes cron-mysql-backup to backup a MySQL database every hour, with email notifications via SendGrid.

const cronMysqlBackup = require('cron-mysql-backup'); let options = { directory: './dumps', cronSchedule: '0 * * * *', connection: { host: 'localhost', user: 'readonly', password: process.env.MYSQL_PASSWORD ?? '', database: 'mydb', }, sendTo: process.env.EMAIL_TO ?? '', sendFrom: process.env.EMAIL_FROM ?? '', sendGridApiKey: process.env.SENDGRID_API_KEY ?? '', sendSuccessEmailAfterXBackups: 10, maxBackups: 168 }; cronMysqlBackup(options);
Debug
Known issues
gotchaThe export is a function, not an object. Using it without calling will silently fail.
fix
Ensure you call cronMysqlBackup(options) after import.
affects: >=1.0.0
gotchaRequired properties: connection.host, connection.user, connection.password, connection.database, sendTo, sendFrom, sendGridApiKey, cronSchedule, directory, maxBackups. Missing any will cause errors.
fix
Provide all required options.
affects: >=1.0.0
deprecatedSendGrid API key is required; no alternative email providers supported.
fix
Obtain a SendGrid API key or fork the package to use other providers.
affects: >=1.0.0
gotchaThe package uses mysql (mysqldump) command internally; mysqldump must be installed and available in PATH.
fix
Install MySQL client tools on the machine.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'cron-mysql-backup'
Module not installed or incorrect require path.
fix
Run 'npm install cron-mysql-backup' and ensure node_modules contains the package.
TypeError: cronMysqlBackup is not a function
Incorrect export import; package exports a function, not an object.
fix
Use 'const cronMysqlBackup = require('cron-mysql-backup')' and then call it as cronMysqlBackup(options).
Error: connect ECONNREFUSED localhost:3306
MySQL server not running or incorrect host/port.
fix
Ensure MySQL is running on localhost:3306 and credentials are correct.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
node-cronrequiredProvides the cron scheduling functionality
nodemailerrequiredUsed to send email notifications (via SendGrid)
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cron-mysql-backup — npm install cron-mysql-backup · libregistry