Automating Backup

From: Richard Sydney-Smith <richard(at)ibisau(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Automating Backup
Date: 2006-02-03 03:40:19
Message-ID: 43E2D0A3.8080802@ibisau.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I presently use the following to export the database and as per my
earleir post hope to have an equivent to do the backup as per:

a) check for time since the last backup
b) if older than <x> hrs
(i) perform a vacuum analyze
(ii) force a call to dbbackup
(iii) add a new record into fsyslog

thanks

R

CREATE OR REPLACE FUNCTION export_database(text)
RETURNS text AS
'
declare
tblname record;
cnt record;
dirchar varchar := ''/''; --char(92); --''/''; -- directory separator
character, char 92 is backslash or / for windows

tname varchar :='''';
tquery varchar :='''';
filename varchar :='''';

begin
if $1 <> '''' then
tname := dirchar||$1||dirchar;
else
tname := dirchar;
end if;

for tblname in select tablename from pg_tables WHERE not(tablename like
''pg_%'') and not(tablename like ''t_%'')
and not(tablename like ''%_list'') order by tablename loop
filename := tname|| lower(tblname.tablename)||''.dat'';
tquery := ''copy '' || tblname.tablename || '' to '' ||
quote_literal(filename)||'' with binary '';
execute tquery;
end loop;

return tquery;
end;

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2006-02-03 03:56:35 Re: logging settings
Previous Message Richard Sydney-Smith 2006-02-03 03:30:24 Automating backup