WPMU DEV is dedicated to supporting advanced users in every possible way. Our Snapshot API Documentation is an ongoing project. Information about new commands will be added here as it becomes available.

6.1 Filters & Actions

Copy chapter anchor to clipboard
Filters
Change root of backups/restores
/lib/snapshot/helper/class-fs.php
Change tables for backup
lib/snapshot/task/backup/class-dblist.php
File restoration size
lib/snapshot/model/restore/class-files.php
Table restoration size
lib/snapshot/model/restore/class-tables.php

6.1.1 Filter: wp_snapshot_home_path

Link to chapter 1

Description

This filter is used to change the site root of the backups/restores. So, using a deeper directory (eg. ‘/var/web/site/public_html/wp-content/uploads‘) in that filter will make Snapshot begin its backups from there instead of the site’s default root directory.

Usage

add_filter( ‘wp_snapshot_home_path’, ‘snapshot_home_path_custom’ );

Example

6.1.2 Filter: snapshot_tables_for_backup

Link to chapter 1

Description

This filter is used to change the list of db tables that will be backed up. So, if it returns wp_posts, only the wp_posts table will be backed up (make sure you use a table that exists in your site).

Similarly, with some PHP code it can be used to exclude specific db tables from your backups (example #2).

Usage

add_filter( ‘snapshot_tables_for_backup’, ‘include_tables’);

Example

#1 Includes only the ‘wp_posts’  table in the backups

#1 Excludes the ‘wp_comments’, ‘wp_commentmeta’ tables from the backups

6.1.3 Filter: snapshot4_model_restore_files_paths_limit

Link to chapter 1

Description

This filter is used to change the size of the batches used for file restoration. If server resources prevent a file restoration to be performed successfully, the user can try a lower batch size (default batch size is 250).

Usage

add_filter( ‘snapshot4_model_restore_files_paths_limit’, ‘files_paths_limit’ );

Example

6.1.4 Filter: snapshot4_model_restore_db_lines_limit

Link to chapter 1

Description

This filter is used to change the size of the batches used for table restoration. If server resources prevent a table restoration to be performed successfully, the user can try a lower batch size (default batch size is 250).

Usage

add_filter( ‘snapshot4_model_restore_db_lines_limit’, ‘db_lines_limit’ );

Example

WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installations and much more, without using a web browser. Snapshot has an integration module with WP CLI, which will allow you to simplify a few common tasks.

Command
wp snapshot backup [command] [id] [args]

Parameters

command
String
Accepts: list, run, download, status, log.
id
String
Optional; use with download or log commands. Accepts: hexadecimal backup ID found using the list command. If no ID is specified, applicable arguments default to the most recent backup.
args
String
Accepts: –name=”Backup name”, –apply-exclusions, –force , –send-email, –errors, –warnings. Note that some arguments can only be used with certain commands; see examples below.

Examples

List all backups and include ID, date, name and size for each:
wp snapshot backup list

Initiate a backup:
wp snapshot backup run

Initiate a backup and give it a name:
wp snapshot backup run --name="Backup name"

Initiate a backup and apply exclusions as set in the plugin UI:
wp snapshot backup run --apply-exclusions

Initiate a backup, give it a name, and apply exclusions as set in the plugin UI:
wp snapshot backup run --name="Backup name" --apply-exclusions

Get a link to download the latest backup:
wp snapshot backup download

Get a link to download a backup specified by ID:
wp snapshot backup download id

Force download the latest backup, even if it was exported earlier:
wp snapshot backup download --force

Force the download of a backup specified by ID:
wp snapshot backup download id --force

Get a link to download the latest backup and also send an email (note that –force is implied when using –send-email):
wp snapshot backup download --send-email

Get a link to download a backup specified by ID and also send an email:
wp snapshot backup download id --send-email

Check if a backup is currently in progress:
wp snapshot backup status

Show the latest backup log:
wp snapshot backup log

Show the log for a backup specified by ID:
wp snapshot backup log id

Show only errors from the latest backup log:
wp snapshot backup log --errors

Show only warnings and errors from the latest backup log:
wp snapshot backup log --warnings

Show only error log for a backup specified by ID:
wp snapshot backup log id --errors

Show only warnings and errors log for a backup specified by ID:
wp snapshot backup log id --warnings