Created
October 24, 2017 16:40
-
-
Save ZeusAFK/d26281fe5ff3621c2a2b6fad3eb94266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* pgBackupRestore PHP Class Benchmark Example | |
* for php-cli | |
* | |
* usage: | |
* php -q example.php - Perform both backup and restore | |
* php -q example.php backup - Perform backup | |
* php -q example.php restore - Perform restore | |
* | |
*/ | |
require("pgBackupRestore.class.php"); | |
// POSTGRESQL AUTH INFO | |
$db_host = "localhost"; | |
$db_user = "postgres"; | |
$db_pass = "secret"; | |
// SOURCE DATABASE (Backup) | |
$source_db="my_database"; | |
// SQL FILE TO BE CREATED | |
$sql_file="my_database.sql"; | |
// DESTINATION DATABASE (Restore) | |
$dest_db="testing"; | |
function timer() | |
{ | |
$time = microtime(); | |
$time = explode(" ", $time); | |
$time = $time[1] + $time[0]; | |
return($time); | |
} | |
switch( strtolower($argv[1]) ) | |
{ | |
case 'backup': | |
$Backup = true; | |
$Restore = false; | |
break; | |
case 'restore': | |
$Backup = false; | |
$Restore = true; | |
break; | |
default: | |
$Backup = true; | |
$Restore = true; | |
break; | |
} | |
printf ("--[ Current Memory Limit: %s\n\n", ini_get('memory_limit')); | |
if ($Backup) | |
{ | |
printf ("[+] Backup of database '$source_db' in progress\n"); | |
$s = timer(); | |
$pgBackup = new pgBackupRestore($db_host, $db_user, $db_pass, $source_db); | |
$pgBackup->UseDropTable = false; | |
$pgBackup->Backup($sql_file); | |
$e = timer(); | |
printf("[+] Backup took %d seconds to terminate\n\n", ($e - $s)); | |
} | |
if ($Restore) | |
{ | |
printf ("[+] Restore to database '$dest_db' in progress\n"); | |
$s = timer(); | |
$pgRestore = new pgBackupRestore($db_host, $db_user, $db_pass, $dest_db); | |
$pgRestore->Restore($sql_file); | |
$e = timer(); | |
printf("[+] Restore took %d seconds to terminate\n\n", ($e - $s)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment