Re: pg_dump shell or php? - Mailing list pgsql-general

From Dan Wilson
Subject Re: pg_dump shell or php?
Date
Msg-id 002001c08db3$34fcd0a0$078353d8@danwilson
Whole thread Raw
In response to pg_dump shell or php?  ("Matt Friedman" <matt@daart.ca>)
List pgsql-general
Here's a simple PHP script that I use.  You can backup only certain
databases or the whole server.  I'm actually planning on making this part of
the phpPgAdmin package.  You can specify how many days you want the backup
files to remain.

-Dan

----------------------------
#!/usr/bin/php -q
<?php
// File:  pg_backup.php
// Purpose:  backup postgres
// Date:  02 Dec 2000
// Author:  Dan Wilson

$data_dir  = "/home/dan/db_backup/data";
$pg_dump_dir = "/usr/bin";
$keep  = (60 * 60 * 24) * 30;  // 30 days

$dbname[]  = "database_name";

$dump_date = date("Ymd_Hs");

$file_name = $data_dir . "/dump_" . $dump_date . ".sql";

// echo date("Y-m-d H:i:s T"), "\n";
if ($cntDB = count($dbname)) {
 for ($iDB = 0; $iDB < $cntDB; $iDB++) {
  system("$pg_dump_dir/pg_dump $dbname[$iDB] >> $file_name");
 }
} else {
 system("$pg_dump_dir/pg_dumpall > $file_name");
}

// echo date("Y-m-d H:i:s T"), "\n";

$dirh = dir($data_dir);
while($entry = $dirh->read()) {
 $old_file_time  = (date("U") - $keep);
 $file_created  = filectime("$data_dir/$entry");
 if ($file_created < $old_file_time && !is_dir($entry)) {
  if(unlink("$data_dir/$entry")) {
  // echo "Delete $data_dir/$entry\n";
  }
 }
}

?>


----- Original Message -----
From: "Matt Friedman" <matt@daart.ca>
To: <pgsql-general@postgresql.org>
Sent: Friday, February 02, 2001 4:53 PM
Subject: [GENERAL] pg_dump shell or php?


Any one written a shell or php script that runs pg_dump on a db say everyday
or something?

Any suggestions?

thanks,

Matt Friedman




pgsql-general by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Installing Postgresql 7 on either RaQ3i or RaQ2
Next
From: Richard Huxton
Date:
Subject: Re: Postgres users/groups