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

3h-backup

v1.1.0

Published

A personal backup helper.

Downloads

18

Readme

3h-backup

A personal backup helper.

Table of Contents

Introduction

3h-backup is a personal backup helper that simply maintains a copy of the files you specified. Its backup mechanism basically makes file structure under destination path the same as source path. The designed purpose of 3h-backup is to backup important files in somewhere like a USB drive.

Usage

  1. It is recommended to install 3h-backup as a global package to have better version control and avoid potential breakage:

    npm install -g 3h-backup
  2. Create a configuration file:

    {
        "tasks": [
            {
                "source": "/path/to/data-root",
                "destination": "/path/to/backup-root",
                "filter": "source"
            }
        ]
    }
  3. Create a list file in your data folder to specify the files you want to include or exclude:

    patterns-to-include
    !patterns-to-exclude
  4. Execute 3h-backup and specifies your config file:

    3h-backup -c /path/to/config

Now, the program should be processing your backup tasks and you can follow the instructions in your terminal to complete your backup.

For more help on the CLI program:

$ 3h-backup --help
A personal backup helper.

Usage:
  3h-backup [options]

Options:
  --help, -h                      Show help info.
  --config, -c <path>             The Path to the config file.
                                  Default: 3h-backup.json
  --tasks, -t <identities...>     Tasks to execute.
                                  Default: execute all tasks
  --encoding, -e <enc>            The encoding of the config file and list files.
                                  Default: utf-8
  --json, -j                      Print tasks in json format.
                                  Default format: simple

List Files

List files are text files that placed in directories to scan and contains the file patterns that you want to include or exclude.

List File Processing

Processing of a single list file follows these steps and rules:

  1. Lines are splitted by \n;
  2. Each line is trimmed to remove beginning and trailing whitespace characters;
  3. Empty lines and lines starting with # are ignored;
  4. Lines starting with ! are regarded as negative patterns that exclude matched files;
  5. Other lines are regarded as positive patterns that include matched files.

Each list file takes effect in its own directory. 3h-backup will scan for list files recursively in each included directory to decide the file list of a task. If a directory is included by a list file in parent directory or by a task config directly, but there are no list files in it, then all the entries(files & sub-directories) will be included. An empty list file makes all the entries in containing directory ignored.

Glob Patterns

The file patterns in list files are processed by fast-glob with { onlyFiles: false, deep: 1 }. That means,

  1. Both files and directories can be matched by patterns in list files;
  2. Patterns in list files take effect only in current path level.

Configuration

Config File

Here, configuration items are described using the following TypeScript code, where BackupConfig is the type of the whole JSON config file:

/**
 * File list filter. (See the subsections below for more info.)
 */
type BackupFilter = (
    | 'intersection'
    | 'source'
    | 'destination'
    | 'union'
);

/**
 * Replace strategy. (See the subsections below for more info.)
 */
type BackupReplace = (
    | 'mtime'
    | 'ctime'
    | 'all'
);

/**
 * Configuration per task. Note that `source`/`destination`
 * can be either an absolute path or a relative path based on
 * the path of the config file.
 */
interface BackupTaskConfig {
    name?: string;
    /**
     * Base path of source files which are going to be backed up.
     */
    source: string;
    /**
     * Path of destination where file copies should be placed.
     */
    destination: string;
    filter?: BackupFilter;
    replace?: BackupReplace;
    /**
     * If this is set to `true`,
     * any empty directory will be removed
     * when the last file in it is deleted.
     */
    removeEmptyDirectory?: boolean;
}

interface BackupConfig {
    tasks: readonly BackupTaskConfig[];
    /**
     * Encoding of list files.
     * @default 'utf-8'
     */
    encoding?: BufferEncoding;
    /**
     * Possible name of list files that
     * tell the program which file to back up.
     * @default ['.3h-backup-list']
     */
    listFiles?: readonly string[];
    /**
     * Default `filter` for all tasks.
     * @default source
     */
    filter?: BackupFilter;
    /**
     * Default `replace` for all tasks.
     * @default mtime
     */
    replace?: BackupReplace;
    /**
     * Default `removeEmptyDirectory` for all tasks.
     * @default true
     */
    removeEmptyDirectory?: boolean;
    /**
     * Whether to skip confirming step.
     * @default false
     */
    skipConfirm?: boolean;
}

Filter

The filter option controls which files should be considered:

  • source(default) -- Include files existing in source path only.
  • destination -- Include files existing in destination path only.
  • intersection -- Intersection of source files and destination files.
  • union -- Union of source files and destination files.

Also, it affects creating new files and removing extra files:

  • source(default) -- Create new files in destination path if there are corresponding source files.
  • destination -- Remove extra files in destination path if corresponding source files don't exist.
  • intersection -- Never create or remove files.
  • union -- Combination of source and destination.

Replace

The replace option tells when to replace an existing destination file:

  • all -- Replace all destination files.
  • mtime(default) -- Replace an existing destination file only if its last-modified time is earlier than that of corresponding source file.
  • ctime -- Replace an existing destination file only if its creation time is earlier than that of corresponding source file.

License

ISC License