Implementing Backup
Introduction
The new FreePBX backup now allows each module to handle their own data. To see modules that implement the new backup you can run the command: fwconsole bu --Implemented
Technical Debt
Please note in 15 the backup and restore methods are removed. Please remove these from the modules BMO class. They are unimplemented.
The Files
Implementation uses 2 classes. One class for each purpose.
rawname/Backup.php
rawname/Restore.php
Skeleton Files
You can copy these from the backup directory then change the module name as required.
[root@freepbx blacklist]# pwd
/usr/src/freepbx/blacklist
[root@freepbx blacklist]# cp ../backup/examples/Backup.php.template Backup.php
[root@freepbx blacklist]# cp ../backup/examples/Restore.php.template Restore.php
[root@freepbx blacklist]# sed -i 's/__MODULENAME__/Blacklist/g' Backup.php
[root@freepbx blacklist]# sed -i 's/__MODULENAME__/Blacklist/g' Restore.php |
The Code
Backup.php
Backup.php
<?php
namespace FreePBX\modules\Recordings;
use FreePBX\modules\Backup as Base;
class Backup Extends Base\BackupBase{
public function runBackup($id,$transaction){
//$this->FreePBX
}
} |
Restore.php
Restore.php
<?php
namespace FreePBX\modules\Recordings;
use FreePBX\modules\Backup as Base;
class Restore Extends Base\RestoreBase{
public function runRestore(){
//$this->FreePBX
//$this->tmpdir
}
} |
Namespaces
The namespace should be FreePBX\modules\Rawname
This module uses FreePBX\modules\Backup as Base
Logging
Backup.php and Restore.php both implement a backend logger which you can utilize as such:
If $level is not set then the default level will be used which is INFO, you can also use the following levels:
DEBUG
NOTICE
WARNING
ERROR
CRITICAL
ALERT
EMERGENCY
INFO
Backup.php
Backup Module Variables
By default the class inherits:
$this→FreePBX: The FreePBX BMO Object
$this→backupObj: The Backup BMO Object
Backup Module Methods
Backup configuration methods
addConfig: Used to add a single configuration to the configs array
addConfigs: Used to add configuration as an array
addDependency: Add a single dependency for this module
addDirectories: Add multiple Directories
addFile: Add Single file to Files List
addSplFile: Similar to addFile except you can use splfile info to generate what you need
Backup Overridable methods
runBackup: This is where your main logic goes. This method is called when a backup is requested
Backup Helper Methods
dumpAll: Dumps all relevant settings into a multidimensional array
dumpAdvancedSettings: Dumps Module's Advanced Settings into an array
dumpFeatureCodes: Dumps module's feature codes into an array
dumpTables: Dumps module's database tables into an array
dumpKVStore: Dumps module's Key Value store entries into an array
Restore.php
Restore Module Variables
By default you will have access to:
$this→FreePBX: The FreePBX BMO Object
$this→backupObj: The Backup BMO Object
$this→tmpdir: Where files are extracted to
Restore Module Methods
Restore configuration methods
getConfigs: Get the configurations as a multidimensional array for said module
getFiles: Gets the file list for said module
getDirectories: Gets the list of directories
getDependencies: Gets the list of dependencies for said module
getVersion: Get's the version of the module being restored
Restore Overridable methods
runRestore: This is where your main logic goes. This method is called when a restore is requested
reset: Typically during restore modules are "reset" by uninstalling and reinstalling the module by executing the reset() method. You can override this in your own class to prevent the default action or perform other actions
Restore Helper Methods
importAll: This function expects a multidimensional array in the format returned from the backup method dumpAll()
importAdvancedSettings: This function expects an array in the format returned from the backup method dumpAdvancedSettings()
importFeatureCodes: This function expects an array in the format returned from the backup method dumpFeatureCodes()
importAstDB: Expects a multidimensional array in the format of key => children => child => value
importTables: This function expects an array in the format returned from the backup method dumpTables()
importKVStore: This function expects an array in the format returned from the backup method dumpKVStore()
addDataToTableFromArray: This is used by the importTables() method above
Legacy Restore
Restore legacy methods are added to the same Restore.php class file as the 15+ restore. They do not conflict.
Legacy Restore Configuration Methods
getVersion: Get's the version of the module being restored
Legacy Restore Overridable methods
processLegacy: Process Legacy Method used by other modules
reset: Typically during restore modules are "reset" by uninstalling and reinstalling the module by executing the reset() method. You can override this in your own class to prevent the default action or perform other actions
Legacy Restore Helper Methods
restoreLegacyAll: Simply send this method the $pdo handler for the temporary database and it will run through all functions below and try to determine what needs to be restored
restoreLegacyDatabaseKvstore: Simply send this method the $pdo handler for the temporary database and it will run through only the database and kvstore methods below and try to determine what needs to be restored
restoreLegacyDatabase: Simply send this method the $pdo handler for the temporary database and it will run through only the database methods below and try to determine what needs to be restored
restoreLegacyFeatureCodes: Simply send this method the $pdo handler for the temporary database and it will run restore only the legacy feature codes
restoreLegacySettings: Simply send this method the $pdo handler for the temporary database and it will run restore only the legacy advanced settings
restoreLegacyKvstore: Simply send this method the $pdo handler for the temporary database and it will run restore only the legacy key/value store