Skip to content
Wordpress backup with Gulp
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Gulp Wordpress Backup

Gulpfile to backup a Wordpress installation for migration.

  • Backup profiles providing alternative options (live/ staging for example)
  • Database Export
    • String replacement with serialized string length fix
    • Table prefix replacement
  • File Archiving
    • Choice of Zip or Tar.gz
    • Whether to only archive certain directories
    • Directory exclusion
    • SSH file upload command generation


  1. Clone to directory outside of Wordpress installation
  2. Execute npm install


Configure the gwb object in package.json


gwb.wppath Path to local Wordpress installation

gwb.dbhost Database host

gwb.dbuser Database user

gwb.dbpass Database password

gwb.dbdatabase Database name

gwb.dbprefix New table prefix

gwb.archiver Archiver to use (zip | tar.gz)

gwb.replace Strings to replace in database (object | false)

gwb.include Directories to only include in archive, subject to gwb.exclude (array | false)

gwb.exclude Directories to exclude from archive (array | false)

gwb.sshUser SSH username (string | false)

gwb.sshHost SSH host (string | false)

gwb.sshPath SSH path to server's Wordpress installation (string | false)


"gwb": {
    "wppath": "../Wordpress",
    "dbhost": "localhost",
    "dbuser": "wordpress",
    "dbpass": "wordpress",
    "dbdatabase": "wordpress",
    "dbprefix": "wp_",
    "archiver": "tar.gz",
    "replace": {
        "localhost": ""
    "include": [
    "exclude": [
    "sshUser": "peabay",
    "sshHost": "",
    "sshPath": "/var/www/html/"


Backup Database and Files


Backup Only Files

gulp files

Backup Only Database

gulp database

Specifying An Alternative Set of Options

Use the --options flag to specify the object key of alternative options. Without this flag 'gwb' will be used. Useful for storing settings for staging and live environments.


Backing up a single site from a multisite is not possible, however backing up an entire multisite is. Remember to replace the domain of each site in the database.

Restoring Files

If SSH details are provided the script will generate a command in package.json to upload the backup and SSH you into the server. To execute this command run:

node run upload

Extracting and Importing

  • Exract the files archive with tar -xvzf files.tar.gz -C .
  • Import the database with mysql -u username -p -h localhost <database name> < database.sql

Import Script

Alternatively you can create a bash script to do this for you.

  • Have the files uploaded outside of the Wordpress installation.
  • Creat a file called in the same location.
  • Give execution permissions with chmod +x
  • In insert the following (edit public_html directory name if different) and execute ./ to run script.

# Extract and delete files.tar.gz
if [ -f ./files.tar.gz ]; then
    tar -xvzf files.tar.gz -C ./public_html && rm ./files.tar.gz

# Extract and delete
if [ -f ./ ]; then
    tar -xvzf -C ./public_html && rm ./

# Import and delete database.sql 
if [ -f ./database.sql ]; then
    mysql -u <database username> -p'<database password>' -h localhost <database name> < database.sql && rm ./database.sql

To download the database or files from the server after generating a backup there execute:

scp ~/Desktop

You can’t perform that action at this time.