The backup is created with pg_dump.
pg_dump -Fc -h "$HOSTNAME" -U "$USERNAME" "$DATABASE" -f $FINAL_BACKUP_DIR"$DATABASE"
To restore it:
Decompress file
gunzip <gz file>
Asure owner is the same that in the file
createdb -U <owner> <database name>
Edit the sql file to change “Owner”’s name to the postgres superuser name.
cp file file.bak
sed 's/old_awner/new_owner/' file.bak > file
rm file.bak
Import database
psql -U new_owner -d <database> -f <sql file created with pg_dump>
#Otra forma
Backup:
$ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}
Restore:
$ psql [--table {table-name}] -U {user-name} -d {destination_db}-f {dumpfilename.sql}
Backup all databases:
#connect as postgres user (optional)
su postgres
#list databases
psql -l
#backup all databases
pg_dumpall
#verify all databases are backed up
grep "^[\]connect" all.sql