Thread: pg_dump shell or php?

pg_dump shell or php?

From
"Matt Friedman"
Date:
Any one written a shell or php script that runs pg_dump on a db say everyday or something?
 
Any suggestions?
 
thanks,

Matt Friedman

Re: pg_dump shell or php?

From
"Mitch Vincent"
Date:
This is simple, but it's what I use to do my daily dumps (run from
crontab) -- I took out some stuff specific to my application..Replace
database with the name of the database..


#!/bin/sh

pgpath=/usr/local/pgsql/bin
homepath=/home/postgres
backup=/usr/local/pgsql/backup
today=`date "+%Y%m%d-%H%M%S"`

$pgpath/pg_dump database > $backup/database${today}dump
/bin/gzip $backup/database${today}dump



----- Original Message -----
From: "Matt Friedman" <matt@daart.ca>
To: <pgsql-general@postgresql.org>
Sent: Friday, February 02, 2001 7:53 PM
Subject: 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




Re: pg_dump shell or php?

From
"Dan Wilson"
Date:
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