WireDatabaseBackup::backup() method

Perform a database export/dump

Usage

// basic usage
$string = $backup->backup();

// usage with all arguments
$string = $backup->backup(array $options = []);

Arguments

NameType(s)Description
options (optional)array

Options to modify default behavior:

  • filename (string): filename for backup: default is to make a dated filename, but this can also be used (basename only, no path)
  • description (string): optional description of this backup
  • tables (array): if specified, export will only include these tables
  • user (string): username to associate with the backup file (string), optional
  • excludeTables (array): exclude creating or inserting into these tables
  • excludeCreateTables (array): exclude creating these tables, but still export data
  • excludeExportTables (array): exclude exporting data, but still create tables
  • whereSQL (array): SQL conditions for export of individual tables [table => [SQL conditions]]. The table portion (index) may also be a full PCRE regexp, must start with / to be recognized as regex.
  • maxSeconds (int): max number of seconds allowed for execution (default=1200)
  • allowDrop (bool): use DROP TABLES statements before CREATE TABLE statements? (default=true)
  • allowUpdate (bool): use UPDATE ON DUPLICATE KEY so that INSERT statements can UPDATE when rows already present (all tables). (default=false)
  • allowUpdateTables (array): table names that will use UPDATE ON DUPLICATE KEY (does NOT require allowUpdate=true)
  • findReplace (array): find and replace in row data during backup. Example: ['databass' => 'database']
  • findReplaceCreateTable (array): find and replace in create table statements Example: ['DEFAULT CHARSET=latin1;' => 'DEFAULT CHARSET=utf8;']
  • extraSQL (array): additional SQL queries to append at the bottom. Example: ['UPDATE pages SET created=NOW()']

Return value

string

Full path and filename of database export file, or false on failure.

Exceptions

Method can throw exceptions on error:

  • \Exception - on fatal error

See Also


$backup methods and properties

API reference based on ProcessWire core version 3.0.168

Twitter updates

  • ProcessWire 3.0.171 dev branch core updates – More
    22 January 2021
  • Preliminary 2021 roadmap in progress in this week’s update— More
    8 January 2021
  • Happy New Year! Today I’ve bumped the version on the dev branch to 3.0.170, and it’s quite a lot of updates. This post covers most of them. In this post, there’s also a question for you: what would you like to see in ProcessWire in 2021? More
    1 January 2021

Latest news

  • ProcessWire Weekly #350
    In the 350th issue of ProcessWire Weekly we'll check out ProcessWire 3.0.171, highlight some recent forum threads and other ProcessWire resources, and introduce a brand new site of the week. Read on!
    Weekly.pw / 23 January 2021
  • ProcessWire 3.0.170 core updates
    Happy New Year! Today I’ve bumped the version on the dev branch to 3.0.170, and it’s quite a lot of updates. This post covers most of them. In this post, there’s also a question for you: what would you like to see in ProcessWire in 2021?
    Blog / 1 January 2021
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK