Guest User

Untitled

a guest
Oct 25th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <?php
  2. /*
  3. * pgBackupRestore PHP Class Benchmark Example
  4. * for php-cli
  5. *
  6. * usage:
  7. * php -q example.php - Perform both backup and restore
  8. * php -q example.php backup - Perform backup
  9. * php -q example.php restore - Perform restore
  10. *
  11. */
  12.  
  13. require("pgBackupRestore.class.php");
  14.  
  15. // POSTGRESQL AUTH INFO
  16. $db_host = "localhost";
  17. $db_user = "postgres";
  18. $db_pass = "secret";
  19. // SOURCE DATABASE (Backup)
  20. $source_db="my_database";
  21. // SQL FILE TO BE CREATED
  22. $sql_file="my_database.sql";
  23. // DESTINATION DATABASE (Restore)
  24. $dest_db="testing";
  25.  
  26. function timer()
  27. {
  28. $time = microtime();
  29. $time = explode(" ", $time);
  30. $time = $time[1] + $time[0];
  31. return($time);
  32. }
  33.  
  34. switch( strtolower($argv[1]) )
  35. {
  36. case 'backup':
  37. $Backup = true;
  38. $Restore = false;
  39. break;
  40.  
  41. case 'restore':
  42. $Backup = false;
  43. $Restore = true;
  44. break;
  45.  
  46. default:
  47. $Backup = true;
  48. $Restore = true;
  49. break;
  50. }
  51. printf ("--[ Current Memory Limit: %s\n\n", ini_get('memory_limit'));
  52.  
  53. if ($Backup)
  54. {
  55. printf ("[+] Backup of database '$source_db' in progress\n");
  56. $s = timer();
  57. $pgBackup = new pgBackupRestore($db_host, $db_user, $db_pass, $source_db);
  58. $pgBackup->UseDropTable = false;
  59. $pgBackup->Backup($sql_file);
  60. $e = timer();
  61. printf("[+] Backup took %d seconds to terminate\n\n", ($e - $s));
  62. }
  63.  
  64. if ($Restore)
  65. {
  66. printf ("[+] Restore to database '$dest_db' in progress\n");
  67. $s = timer();
  68. $pgRestore = new pgBackupRestore($db_host, $db_user, $db_pass, $dest_db);
  69. $pgRestore->Restore($sql_file);
  70. $e = timer();
  71. printf("[+] Restore took %d seconds to terminate\n\n", ($e - $s));
  72. }
  73. ?>
Add Comment
Please, Sign In to add comment