Re: how to detect the backup database every day

Lists: pgsql-general
From: son(at)raider(dot)co(dot)nz
To: pgsql-general(at)postgresql(dot)org
Subject: how to detect the backup database every day
Date: 2007-08-07 06:09:35
Message-ID: 59398.202.78.240.7.1186466975.squirrel@www.raider.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hello all

I use a crontab job to backup and restore my database every midnight every
day (using pg_dump and restore...)

My cron job run well for a while. However, today I discovered that my
database was not restored for one month.

I also fix the problem as there is corruption in the script.

My question is how I can detect whether the backup or restore processes is
corrupted. I donot want that my backup database is one month old -:(

Is there a solution around this.

If you have any experience about this please help...

Regards


From: Richard Huxton <dev(at)archonet(dot)com>
To: son(at)raider(dot)co(dot)nz
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to detect the backup database every day
Date: 2007-08-07 12:28:07
Message-ID: 46B86557.50901@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

son(at)raider(dot)co(dot)nz wrote:
> Hello all
>
> I use a crontab job to backup and restore my database every midnight every
> day (using pg_dump and restore...)
>
> My cron job run well for a while. However, today I discovered that my
> database was not restored for one month.
>
> I also fix the problem as there is corruption in the script.
>
> My question is how I can detect whether the backup or restore processes is
> corrupted. I donot want that my backup database is one month old -:(

Well, if the script failed with an error, cron should have sent you an
email (or the user the script runs as, anyway).

If you didn't have an error, you could run a separate cron that checks
whether there are recent backup files and emails you if not (find ...
-mtime -1).

Or, if you want to make sure the restore has worked check the database
for a row with a recent timestamp.

--
Richard Huxton
Archonet Ltd


From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "son(at)raider(dot)co(dot)nz" <son(at)raider(dot)co(dot)nz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to detect the backup database every day
Date: 2007-08-07 14:42:41
Message-ID: dcc563d10708070742v36a4de38ue09980d87a860cfa@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 8/7/07, son(at)raider(dot)co(dot)nz <son(at)raider(dot)co(dot)nz> wrote:
> Hello all
>
> I use a crontab job to backup and restore my database every midnight every
> day (using pg_dump and restore...)

Backup from one machine, restore to another, right?

> My cron job run well for a while. However, today I discovered that my
> database was not restored for one month.

> I also fix the problem as there is corruption in the script.
>
> My question is how I can detect whether the backup or restore processes is
> corrupted. I donot want that my backup database is one month old -:(

You can detect whether backup failed from a bash script like so:

#!/bin/bash
if ( pg_dump dbname ); then
echo "good";
else
echo "bad";
fi;

Same thing for pg_restore or psql

> If you have any experience about this please help...

Some. There are a lot of angles you can approach this from. You can
have a simple cronjob that runs every day that checks the size / age
of the latest backup and sends an alarm if it's smaller than the last
one, or isn't there, etc... You can use the find command to look for
files that are less than x seconds / minutes / hours / days old.


From: brian <brian(at)zijn-digital(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: how to detect the backup database every day
Date: 2007-08-07 14:48:16
Message-ID: 46B88630.80700@zijn-digital.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Richard Huxton wrote:
> son(at)raider(dot)co(dot)nz wrote:
>
>> Hello all
>>
>> I use a crontab job to backup and restore my database every midnight
>> every
>> day (using pg_dump and restore...)
>>
>> My cron job run well for a while. However, today I discovered that my
>> database was not restored for one month.
>>
>> I also fix the problem as there is corruption in the script.
>>
>> My question is how I can detect whether the backup or restore
>> processes is
>> corrupted. I donot want that my backup database is one month old -:(
>
>
> Well, if the script failed with an error, cron should have sent you an
> email (or the user the script runs as, anyway).
>

To expand on that, have a look at your crontab and ensure that the call
to your script does not end with ">/dev/null 2>&1". That will cause the
script to run silently, regardess of any errors. If you want it to be
silent yet have errors emailed to you, change it to ">/dev/null"
(without the quotes).

If the emails have been sent but this is an account on a remote server
you might want to investigate having the emails for that remote account
sent to your regular email address.

brian