backupRestore
in package
Class for creating and restoring database backups.
Note that this does not create a standalone SQL backupg but data stored as serialized arrays that the restoreBackup() method turns into SQL statements. For an actual SQL update use tools like phpmyadmin or the commandline "mysqldump".
Basic usage:
$backuprestore = new backupRestore(); // The constructor does not have any parameteres. Options are set via the class property $backuprestore->compression_handler = 'no';
$backuprestore->createBackup(); or $backuprestore->restoreBackup($backupfile); // file name without path and suffix
Tags
Table of Contents
Properties
- $autobackup : bool
- Default false. Enables autobackup mode used for running via zp crons
- $backupfile : mixed
- $buffer : mixed
- $compression_handler : string
- Default "no" for no compression. This is set via createBackup() and restoreBackup() internally depending on the compression level < 1 and bzip or gzio depending on system availability
- $compression_level : int
- Default 0. Any value larger larger than one enables compression
- $db_prefix : mixed
- $db_prefix_length : mixed
- $debuglog_messages : mixed
- $errors : mixed
- $file_version : mixed
- $header : mixed
- $messages : mixed
- $missing_element : mixed
- $missing_table : mixed
- $record_separator : mixed
- $respond_counter : mixed
- $signature : mixed
- $table_separator : mixed
Methods
- __construct() : mixed
- Set options via properties before creating or restoring backups
- compressRow() : type
- Compresses a row if a compression level is set to 1 or higher
- createBackup() : mixed
- Creates a database backup
- decompress() : type
- Decompresses field or row data which is set within restoreBackup()
- extendExecution() : mixed
- "Extends" the PHP script execution by defining a time limit and echoing empty content
- fillBuffer() : bool
- Fills the buffer on reading data from the file handle
- getRow() : bool
- Gets a row from the file handle resource
- printMessages() : mixed
- Prints messages like success or error notices generated by creating or restoring a backup
- restoreBackup() : mixed
- Restores a backup
- writeHeader() : int|false
- Writes header information to the first lines of a backup file
Properties
$autobackup
Default false. Enables autobackup mode used for running via zp crons
public
bool
$autobackup
= \false
$backupfile
public
mixed
$backupfile
= ''
$buffer
public
mixed
$buffer
= ''
$compression_handler
Default "no" for no compression. This is set via createBackup() and restoreBackup() internally depending on the compression level < 1 and bzip or gzio depending on system availability
public
string
$compression_handler
= 'no'
$compression_level
Default 0. Any value larger larger than one enables compression
public
int
$compression_level
= \false
$db_prefix
public
mixed
$db_prefix
= ''
$db_prefix_length
public
mixed
$db_prefix_length
= ''
$debuglog_messages
public
mixed
$debuglog_messages
= \false
$errors
public
mixed
$errors
= array()
$file_version
public
mixed
$file_version
= 1
$header
public
mixed
$header
= '__HEADER__'
$messages
public
mixed
$messages
= ''
$missing_element
public
mixed
$missing_element
= array()
$missing_table
public
mixed
$missing_table
= array()
$record_separator
public
mixed
$record_separator
= ':****:'
$respond_counter
public
mixed
$respond_counter
= 1000
$signature
public
mixed
$signature
= ''
$table_separator
public
mixed
$table_separator
= '::'
Methods
__construct()
Set options via properties before creating or restoring backups
public
__construct() : mixed
compressRow()
Compresses a row if a compression level is set to 1 or higher
public
compressRow(sting $str, int $lvl) : type
Parameters
- $str : sting
-
Data to compress
- $lvl : int
-
Block size during compression
Return values
typecreateBackup()
Creates a database backup
public
createBackup() : mixed
decompress()
Decompresses field or row data which is set within restoreBackup()
public
decompress(sting $str) : type
Parameters
- $str : sting
-
Data to compress
Return values
typeextendExecution()
"Extends" the PHP script execution by defining a time limit and echoing empty content
public
extendExecution() : mixed
fillBuffer()
Fills the buffer on reading data from the file handle
public
fillBuffer(resource $handle) : bool
Parameters
- $handle : resource
-
Backup file resource
Return values
boolgetRow()
Gets a row from the file handle resource
public
getRow(resource $handle) : bool
Parameters
- $handle : resource
-
Backup file resource
Return values
boolprintMessages()
Prints messages like success or error notices generated by creating or restoring a backup
public
printMessages() : mixed
restoreBackup()
Restores a backup
public
restoreBackup(string $backupfile) : mixed
Parameters
- $backupfile : string
-
The file name without path and suffix to restore from
writeHeader()
Writes header information to the first lines of a backup file
public
writeHeader(string $type, string $value, resource $handle) : int|false
Parameters
- $type : string
-
Header type "file_version" or "compression_handler"
- $value : string
-
Header type value
- $handle : resource
-
Backup file resource