Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michele Brodoloni  >  PostgreSQL Backup and Restore  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: PostgreSQL Backup and Restore
Backup and restore PostgreSQL databases with files
Author: By
Last change: Remove useless duplicate function (timer_start, timer_stop)
Date: 2007-09-25 03:57
Size: 1,904 bytes
 

Contents

Class file image Download
<?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));
   }
?>