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

@gebruederheitz/wp-backup

v1.0.0

Published

Create database and userdata backups for staggered Wordpress releases.

Downloads

7

Readme

wp-backup

Create database and userdata backups for staggered Wordpress releases.


Installation

Via GitHub

Check the "Assets" field in the latest GitHub release to download the compiled binary for Linux x64.

Via ghdev

For now, the built binary will also be hosted on ghdev.de. This is probably not permanent and is not guaranteed to be up to date.

  • https://cdn.ghdev.de/wp-backup/wp-backup

Via NPM

Use NPM to install this package for direct usage:

$> npm i @gebruederheitz/wp-backup
# Then you can use
$> npx wp-backup
# or
$> ./node_modules/.bin/wp-backup

Usage

This application is meant to be used with "staggered" Wordpress releases. It assumes the following project structure:

<project directory>
 |
 |-- backup/               # Where backups will be stored
 |-- configuration/        # Optional
 |   |-- .env              # Optional - DB config can be read from this
 |
 |-- (public/, releases/, ...)
 |-- userdata/             # This will be backed up when using -U or -a
 |   |-- uploads/
 |   |-- plugins/
 |   |-- languages/
 |   |-- ...

In this setup, the build releases are written to releases/, with the current release being symlinked from public/. The userdata/ directory's contents are them symlinked into each release, as these files are specific to the instance and remain across releases.

wp-backup creates (and restores) two types of backup:

  • the database (using mysqldump, which must be present on the system)
  • the userdata directory (by zipping the entire directory content).

The -h flag will show you a list of available options and some usage information. You can however just execute the program without any options and have the wizard guide you through creating or restoring your Wodpress backups.

# Start the wizard
$> wp-backup

# Get help
$> wp-backup -h

# Provide some settings and have the wizard ask for the rest
$> wp-backup backup -d ~/projects/my-wp-site/htdocs

# Skip the wizard, don't ask questions: Run a backup of userdata & DB in the 
# current directory
$> wp-backup backup -na

Dependencies

  • GNU coreutils (readlink, whoami, realpath)
  • mysqldump

Configuration

Database config

There are three ways to configure the database connection used by mysql / mysqldump:

  • Using the dotenv file (default, file must be in <project_dir>/configuration/.env)
  • Using a custom YAML configuration (.wp-backup.yaml, either in the pwd when using -c or specified by -C /path/to/.wp-backup.yaml)
  • Passing a "database URL" to -x mysql://user:pass@host:port/database/prefix (port, database name and table prefix are optional and can be omitted – they will fall back to their defaults 3306 / wordpress / wp_; however in order to set a prefix the database name must be provided.)
Dotenv

The following fields are read from configuration/.env:

DB_NAME=database       # default "worpdress"
DB_USER=user
DB_PASSWORD=pass
DB_HOST=localhost      # default "127.0.0.1" so as not to accidentally use sockets
DB_TABLE_PREFIX=prefix # default "wp_"
DB_PORT=port           # default "3306"

Any value not set will fall back to its default; user and password are always required.

YAML

Pass the -c or --config flag to read the .wp-backup.yaml from the current working directory. With the option -C <path> or --config-file=<path> you can use a file in a different location.

# .wp-backup.yaml
db:
  host: host
  user: user
  pass: pass
  port: port
  prefix: prefix
  database: database

Any value not set will fall back to its default (see above); user and password are always required.

You can also use the YAML config to provide a "database URL":

db: mysql://user:pass@host:port/db/prefix
DB-URL

You can also provide a database URL string on the command line, overriding any settings read from dotenv or YAML:

# Create a database backup tagged "--testing-db-url-setup" without running the
# wizard for additional configuration on the database "db" on "host:port".
$> wp-backup backup -Dn -x mysql://user:pass@host:port/db/prefix -c "testing db url setup" 

Some parts of this URL-style string are optional:

# the mysql:// prefix is optional 
user:pass@host
# the username, password and hostname must always be provided
mysql://user:pass@host
# the port can be omitted
mysql://user:pass@host/db
# in order to supply a table prefix, the database name must be provided
mysql://user:pass@host/db/prefix
mysql://user:pass@host:port/db

Development

Dependencies

Recommended

  • GNU Make or drop-in alternative
  • NodeJS 16.x (for publishing to NPM)
# Install dependencies
$> dart pub get
# Pack & Compile everything (recommended once)
$> make package
# Run through Dart runtime
$> dart dist/wp-backup.dart