public inbox for [email protected]  
help / color / mirror / Atom feed
Restoring database from backup
4+ messages / 2 participants
[nested] [flat]

* Restoring database from backup
@ 2024-12-13 18:21  Rich Shepard <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Rich Shepard @ 2024-12-13 18:21 UTC (permalink / raw)
  To: pgsql-general

I made a careless error this morning and want to restore the database from
yesterday's backup, `bustrac-2024-12-12.sql'. If I run

psql -d bustrac -f bustrac-2024-12-12.sql

will this restore the database to yesterday's status without first
deleting/removing the FUBAR'd one?

TIA,

Rich






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Restoring database from backup
@ 2024-12-13 18:31  Adrian Klaver <[email protected]>
  parent: Rich Shepard <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Adrian Klaver @ 2024-12-13 18:31 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; pgsql-general



On 12/13/24 10:21 AM, Rich Shepard wrote:
> I made a careless error this morning and want to restore the database from
> yesterday's backup, `bustrac-2024-12-12.sql'. If I run
> 
> psql -d bustrac -f bustrac-2024-12-12.sql
> 
> will this restore the database to yesterday's status without first
> deleting/removing the FUBAR'd one?

This needs more information:

1) Have you backed up your database at the current state?

2) What command did you use to create bustrac-2024-12-12.sql?

> 
> TIA,
> 
> Rich
> 
> 

-- 
Adrian Klaver
[email protected]






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Restoring database from backup
@ 2024-12-13 19:18  Rich Shepard <[email protected]>
  parent: Adrian Klaver <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Rich Shepard @ 2024-12-13 19:18 UTC (permalink / raw)
  To: pgsql-general

On Fri, 13 Dec 2024, Adrian Klaver wrote:

> This needs more information:
>
> 1) Have you backed up your database at the current state?

Adrian,

No, the current state is FUBAR'd. The cron backup script runs each night at
11:15 p.m.

> 2) What command did you use to create bustrac-2024-12-12.sql?

!/usr/bin/bash
#
# This script pg_dump to save the database w/date stamp

cd /data1/database-backups/
pg_dump -d bustrac -c -f bustrac-$(date +%Y-%m-%d).sql 
cd

Thanks,

Rich






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Restoring database from backup
@ 2024-12-13 19:23  Adrian Klaver <[email protected]>
  parent: Rich Shepard <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Adrian Klaver @ 2024-12-13 19:23 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; pgsql-general



On 12/13/24 11:18 AM, Rich Shepard wrote:
> On Fri, 13 Dec 2024, Adrian Klaver wrote:
> 
>> This needs more information:
>>
>> 1) Have you backed up your database at the current state?
> 
> Adrian,
> 
> No, the current state is FUBAR'd. The cron backup script runs each night at
> 11:15 p.m.
> 
>> 2) What command did you use to create bustrac-2024-12-12.sql?
> 
> !/usr/bin/bash
> #
> # This script pg_dump to save the database w/date stamp
> 
> cd /data1/database-backups/
> pg_dump -d bustrac -c -f bustrac-$(date +%Y-%m-%d).sql cd

Alright, from here:

https://www.postgresql.org/docs/current/app-pgdump.html

"-c
--clean

     Output commands to DROP all the dumped database objects prior to 
outputting the commands for creating them. This option is useful when 
the restore is to overwrite an existing database. If any of the objects 
do not exist in the destination database, ignorable error messages will 
be reported during restore, unless --if-exists is also specified.

     This option is ignored when emitting an archive (non-text) output 
file. For the archive formats, you can specify the option when you call 
pg_restore.
"

This means when you run the script with:

psql -d bustrac -f bustrac-2024-12-12.sql

it will clean out the current corrupted objects and replace them with 
those in the backup file.


> 
> Thanks,
> 
> Rich
> 
> 

-- 
Adrian Klaver
[email protected]






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2024-12-13 19:23 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-13 18:21 Restoring database from backup Rich Shepard <[email protected]>
2024-12-13 18:31 ` Adrian Klaver <[email protected]>
2024-12-13 19:18   ` Rich Shepard <[email protected]>
2024-12-13 19:23     ` Adrian Klaver <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox