npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

backupdbtos3-commonjs

v1.0.3

Published

Backup Mysql DB to AWS S3 Using CommonJS

Downloads

256

Readme

MySQL S3 Backup (CommonJS) - Exaland Concept

A simple library for backing up MySQL databases to AWS S3 using the AWS SDK. This package provides an easy way to create a database backup and store it securely in an S3 bucket.

Installation

You can install this package via npm:

npm install backupdbtos3-commonjs

Configuration des Variables d'Environnement

Avant de lancer l'application, vous devez configurer certaines variables d'environnement nécessaires pour le bon fonctionnement de l'application.

Vous pouvez ajouter les variables suivantes dans votre fichier .env :

AWS_REGION=your_aws_region
AWS_ACCESS_KEY_ID=your_access_key_id
AWS_SECRET_ACCESS_KEY=your_secret_access_key
AWS_BUCKET_NAME=your_s3_bucket_name
BACKUP_FILE_NAME=your_backup_file_name_prefix
BACKUP_FILE_PATH=your_backup_file_path
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
WEBHOOK_PORT=3000  # (optionnel, port pour le webhook)

Description des Variables

  • AWS_REGION: La région AWS où se trouve votre bucket S3.
  • AWS_ACCESS_KEY_ID: Votre clé d'accès AWS.
  • AWS_SECRET_ACCESS_KEY: Votre clé secrète AWS.
  • AWS_BUCKET_NAME: Le nom de votre bucket S3.
  • BACKUP_FILE_NAME: Le préfixe du nom du fichier de sauvegarde.
  • BACKUP_FILE_PATH: Le chemin d'accès où le fichier de sauvegarde sera stocké.
  • DB_USER: Le nom d'utilisateur de votre base de données.
  • DB_PASSWORD: Le mot de passe de votre base de données.
  • DB_NAME: Le nom de votre base de données.
  • WEBHOOK_PORT: (Optionnel) Port du serveur webhook pour lancer des sauvegardes à distance.

Initialisation et 🚀

const MySqlS3Backup = require("backupdbtos3-commonjs");

// Avec planification automatique (par défaut tous les jours à 2h)
const backup = new MySqlS3Backup();

backup.runBackupProcess()
  .then((result) => {
    console.log("Backup process completed successfully.", result);
  })
  .catch((err) => {
    console.error("Error during backup process:", err);
  });

Planification Cron (Optionnelle)

Pour définir une fréquence automatique, passez une chaîne de syntaxe cron lors de l'initialisation. Si vous ne souhaitez pas de planification automatique, vous pouvez passer false :

// Planification tous les heures
const backupHourly = new MySqlS3Backup('0 * * * *');

// Désactiver la planification automatique
const backupSansCron = new MySqlS3Backup(false);

Note : Si vous ne spécifiez pas de paramètre ou si vous passez true, la planification ne sera pas activée. La valeur false désactive la planification automatique.

Fonctionnalité de Webhook

Pour automatiser le lancement de sauvegardes à distance ou via une plateforme tierce, la librairie inclut maintenant une fonctionnalité de Webhook.

Comment ça marche ?

  • La librairie démarre un serveur HTTP (avec Express) qui écoute sur le port défini dans la variable WEBHOOK_PORT (par défaut 3000).
  • Lorsqu'une requête POST est envoyée à l'endpoint /webhook/backup, la sauvegarde est lancée automatiquement.

Exemple d'utilisation

  1. Démarrez votre script principal, qui initialise la classe et démarre le serveur webhook :
const MySqlS3Backup = require("backupdbtos3-commonjs");

const backup = new MySqlS3Backup();
console.log("Webhook server is listening...");
  1. Envoyez une requête POST à l'endpoint pour déclencher une sauvegarde :
curl -X POST http://localhost:3000/webhook/backup

Sécurité

  • Pensez à sécuriser votre webhook (authentification, IP whitelist, etc.) pour éviter tout déclenchement non autorisé.

Remarque

Assurez-vous de ne jamais inclure vos vraies clés d'accès et autres informations sensibles dans votre code source, surtout si vous le partagez sur des plateformes publiques. Il est recommandé d'utiliser un fichier .env local et d'ajouter ce fichier au .gitignore.