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 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-db-sqlite-cloud-backup

v0.2.19

Published

Backup script for Strapi SQLite DB file

Downloads

38

Readme

strapi-db-sqlite-cloud-backup

Script for scheduled backup to Yandex Drive or Google Drive of a temporary copy of the Strapi SQLite database.

Installation

To use this package, you need to install it in your project:

npm install strapi-db-sqlite-cloud-backup

Initialization

First, you need to initialize the backup configuration by creating a .env file with the necessary environment variables. You can do this using the init command provided by the package:

npx strapi-db-sqlite-cloud-backup init

This will create a .env file in the root of your project. Fill in the required values:

GOOGLE_DRIVE_FOLDER_ID=your-google-drive-folder-id
GOOGLE_CREDENTIALS_PATH=./path/to/google-credentials.json
GOOGLE_DRIVE_ENABLED=false

YANDEX_TOKEN=your-yandex-o-auth-token
YANDEX_DISK_ENABLED=true
YANDEX_BACKUP_PATH=/backups

DB_PATH=../backend/.tmp
DB_NAME=data.db

This will also create an ecosystem.config.js file and fill it with that:

module.exports = {
  apps: [
    {
      name: 'backup',
      script: 'node_modules/strapi-db-sqlite-cloud-backup/backup.js',
      args: 'run',
      cron_restart: '0 */3 * * *', // Run every 3 hours
      watch: false,
      env: {
        NODE_ENV: 'production'
      }
    }
  ]
};

Change the backup timeout value if needed.

Usage

To run the backup script manually, use the run command:

npx strapi-db-sqlite-cloud-backup run

This command will perform a one-time backup of the database according to the steps outlined below.

Workflow

The logic that this script follows includes several key steps:

  1. Initialization of configurations and logger:

    • Environment variables are loaded from the .env file.
    • A logger is set up using the winston library.
  2. Defining paths:

    • Paths to the database, backup directory, and log files are determined.
  3. Creating a database backup:

    • The backup directory is created if it does not exist.
    • The database file is copied to the backup directory.
    • A log message is recorded about the creation of the backup.
  4. Uploading the backup to cloud storage (Google Drive and Yandex Disk):

    • If the environment variables GOOGLE_DRIVE_ENABLED and YANDEX_DISK_ENABLED are set to true, the backup is uploaded to the respective cloud storage services.
    • Log messages about the process and the result of the upload is recorded.
  5. Managing the number of backups:

    • The number of backups in the backup directory is checked.
    • If the number of backups exceeds the set limit (MAX_BACKUPS), the oldest backups are deleted.
    • Log messages about the process and result of deleting old backups are recorded.
  6. Starting the script via the pm2 process manager:

  7. To start the script at scheduled intervals and ensure it restarts in case of failures, you can use the pm2 process manager. Create an ecosystem.config.js file in your project root with the following content:

module.exports = {
  apps: [
    {
      name: 'backup',
      script: 'node_modules/strapi-db-sqlite-cloud-backup/backup.js',
      cron_restart: '0 */3 * * *', // Run every 3 hours
      watch: false,
      env: {
        NODE_ENV: 'production',
        // Environment variables for the script
        GOOGLE_DRIVE_ENABLED: process.env.GOOGLE_DRIVE_ENABLED,
        YANDEX_DISK_ENABLED: process.env.YANDEX_DISK_ENABLED,
        GOOGLE_DRIVE_FOLDER_ID: process.env.GOOGLE_DRIVE_FOLDER_ID,
        GOOGLE_CREDENTIALS_PATH: process.env.GOOGLE_CREDENTIALS_PATH,
        YANDEX_TOKEN: process.env.YANDEX_TOKEN,
        YANDEX_BACKUP_PATH: process.env.YANDEX_BACKUP_PATH,
        DB_PATH: process.env.DB_PATH,
        DB_NAME: process.env.DB_NAME
      }
    }
  ]
};

Then start the script using pm2:

pm2 start ecosystem.config.js

By following these steps, you can set up scheduled backups of your Strapi SQLite database to either Google Drive or Yandex Disk.