Re: pg_dump shell or php?

From: "Dan Wilson" <phpPgAdmin(at)acucore(dot)com>
To: "Matt Friedman" <matt(at)sprynewmedia(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: pg_dump shell or php?
Date: 2001-02-03 07:30:37
Message-ID: 002001c08db3$34fcd0a0$078353d8@danwilson
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)daart(dot)ca>
To: <pgsql-general(at)postgresql(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2001-02-03 10:26:30 Re: Postgres users/groups
Previous Message Tatsuo Ishii 2001-02-03 03:10:44 Re: Installing Postgresql 7 on either RaQ3i or RaQ2