Skip to content

Snapshots

Snapshots capture a sandbox recovery point.

Shell
wp rudel snapshot alpha-3be7 --name=before-test

Restore a snapshot:

Shell
wp rudel restore alpha-3be7 --snapshot=before-test

restore asks for confirmation; --force skips the prompt. Snapshot names are up to 64 letters, digits, dots, dashes or underscores, starting with a letter or digit.

Snapshots are for sandbox recovery, not for runtime identity. The environment record remains the source of truth for the sandbox. A snapshot belongs to one sandbox and can only be restored into that sandbox. To start new sandboxes from a saved state, use Templates instead.

Create and restore from WP-CLI

This flow saves a known state, changes the sandbox, and rolls the change back. The full command reference is on CLI.

Create a sandbox. The ID is the name plus four hex characters, and the command prints it in its success line, followed by a clone summary and the sandbox path:

Shell
wp rudel create --name=alpha
Text
Success: Sandbox created: alpha-3be7

Set a value inside the sandbox. RUDEL_ENVIRONMENT runs any WP-CLI command against the sandbox tables instead of the host:

Shell
RUDEL_ENVIRONMENT=alpha-3be7 wp option update blogname "Alpha Site"

Save the current state as a snapshot named baseline:

Shell
wp rudel snapshot alpha-3be7 --name=baseline
Text
Success: Snapshot created: baseline

Change the sandbox, for example by running a migration, activating a plugin, or editing an option:

Shell
RUDEL_ENVIRONMENT=alpha-3be7 wp option update blogname "Alpha Changed"

Restore the snapshot. Without --force, WP-CLI asks Are you sure you want to restore sandbox 'alpha' from snapshot 'baseline'? first:

Shell
wp rudel restore alpha-3be7 --snapshot=baseline --force
Text
Success: Sandbox restored from snapshot: baseline

The sandbox tables are back at the saved state:

Shell
RUDEL_ENVIRONMENT=alpha-3be7 wp option get blogname
Text
Alpha Site

Delete the snapshot once it is no longer needed:

Shell
wp rudel snapshot delete alpha-3be7 --name=baseline
Text
Success: Snapshot deleted: baseline

The commands stop with an error in these cases:

Situation Message
The name breaks the naming rule Invalid snapshot name: <name>
snapshot reuses an existing name Snapshot already exists: <name>
restore names a missing snapshot Snapshot not found: <name>
snapshot delete names a missing snapshot Snapshot not found: <name>

WP-CLI has no command that lists snapshots. Use Rudel::snapshots() through wp eval:

Shell
wp eval 'print_r( Rudel\Rudel::snapshots( "alpha-3be7" ) );'

Create and restore from PHP

The same flow through the static facade. Each method is described on API.

PHP
use Rudel\Rudel;

$sandbox = Rudel::create( 'alpha' );

$meta = Rudel::snapshot( $sandbox->id, 'baseline' );

Rudel::restore( $sandbox->id, 'baseline' );

foreach ( Rudel::snapshots( $sandbox->id ) as $snapshot ) {
    printf( "%s %s\n", $snapshot['name'], $snapshot['created_at'] );
}

Rudel::delete_snapshot( $sandbox->id, 'baseline' );

Rudel::snapshot() returns the snapshot metadata: name, created_at (an ISO 8601 UTC timestamp) and sandbox_id. Rudel::snapshots() returns the same keys for every snapshot, newest first. After the restore above, the list holds baseline and the automatic pre-restore-... snapshot described below.

The PHP methods do not ask for confirmation. They throw instead of printing errors:

  • Rudel::snapshot(), Rudel::restore(), Rudel::snapshots() and Rudel::delete_snapshot() throw a RuntimeException when the sandbox does not exist.
  • Rudel::snapshot() throws an InvalidArgumentException when the name is invalid or already used.
  • Rudel::restore() throws a RuntimeException when the snapshot does not exist, and an InvalidArgumentException when the name is invalid.
  • Rudel::delete_snapshot() returns false when the snapshot does not exist.

Undo a restore

By default Rudel saves the current state as a snapshot named pre-restore-{timestamp}-{hash} before every restore, for example pre-restore-20261107_101500-9c1e. The timestamp is UTC in Ymd_His form. To undo a restore, restore that snapshot:

Shell
wp rudel restore alpha-3be7 --snapshot=pre-restore-20261107_101500-9c1e --force

That restore saves another pre-restore-... snapshot of its own, so repeated restores accumulate snapshots until they are deleted or pruned. Set auto_snapshot_before_restore to 0 in rudel_config to turn the automatic snapshot off (see Configuration).

What snapshots capture

  • every table with the sandbox prefix, users included, copied in the same database under {sandbox_prefix}snap_{hash}_, for example wp_b65338d_snap_3ba676_options
  • the sandbox theme directory, copied to snapshots/{name}/themes in the sandbox directory
  • metadata in the host Rudel artifacts table; older JSON metadata is migrated and removed
  • local Git-created plugin overrides, when present

Snapshot files are protected from Apache requests by directory deny rules. On servers that do not read .htaccess, deny HTTP access to the private recovery directories in the server configuration.

A snapshot therefore costs a full copy of the sandbox tables in the host database plus a copy of the theme files.

What snapshots do not capture

  • host WordPress core
  • shared plugin files
  • shared uploads

A restore leaves these untouched. Media files uploaded after the snapshot stay on disk, while their attachment rows go back to the saved state.

Restore

A restore drops the sandbox tables (keeping snapshot tables), copies the snapshot tables back, and replaces the sandbox theme directory and captured local plugin overrides with the saved copies.

Creating or restoring a snapshot records activity on the sandbox (last_used_at), which the idle rule in Cleanup reads.

Listing and removing

From PHP, Rudel::snapshots( $id ) lists snapshots, newest first. Delete one with wp rudel snapshot delete <id> --name=<name> or Rudel::delete_snapshot( $id, $name ). Deletion removes its tables and directory while preserving the sandbox's live tables. Destroying a sandbox deletes all of its snapshots first.

SnapshotManager::prune( $keep ) keeps the newest positive number of snapshots and returns the names it removed; a non-positive value leaves them unchanged. It counts every snapshot, named and automatic alike:

PHP
use Rudel\Rudel;
use Rudel\SnapshotManager;

$sandbox = Rudel::get( 'alpha-3be7' );

if ( $sandbox ) {
    $removed = ( new SnapshotManager( $sandbox ) )->prune( 5 );
}

Hooks

Creating, restoring and deleting a snapshot fire before, after and failed actions, for example rudel_after_recovery_point_create with the snapshot metadata. The arguments are listed on Hooks.