4

I'm working on PostgreSQL 8.4 and I'd like to do backup and restore (from Ubuntu 11.10 to Ubuntu 12.4)

I want to include all partitions, clusters, roles and stuff.

My commands: Back up:

dumb_all > filename 

Compress:

zip -f mybackup

Uncompress and restore:

sudo gunzip -c /home/ubuntu/Desktop/backupFile.zip | psql -U postgres

The issue is in the restore process, I got an error

invalid command \.
ERROR:  syntax error at or near "2"
LINE 1: 2 2 1
        ^
invalid command \.
ERROR:  syntax error at or near "1"
LINE 1: ...
        ^
out of memory

Plus, the tables with partitions did not restored. also some tables restored without any data!

Please help!

EDIT

I used pgAdmin to do the back up, using the "backup server" option.

backup

5
  • 1
    You could post here the commands that you really used, as the problem may reside on them... Seriously, just copy and paste here... Commented Oct 8, 2013 at 14:43
  • I added some details and I changed the compress command Commented Oct 9, 2013 at 6:40
  • 1
    How about the restore, how did you do? After pgAdmin have you compressed the result? How? Commented Oct 9, 2013 at 12:28
  • the same commands in the question. I did the backup using dump_all then compressed the result using zip -f mybackup then uncompressed and restored it in another DB using one command sudo gunzip -c /home/ubuntu/Desktop/backupFile.zip | psql -U postgres Do you have a better method? Commented Oct 10, 2013 at 7:35
  • No, you didn't!!! How zip -f mybackup would generate a file named backupFile.zip? Anyway, I think I guessed your problem, see my answer... Commented Oct 10, 2013 at 12:20

1 Answer 1

3

If you did used zip to compress the output, then you should use unzip do uncompress it, not gunzip, they use different formats/algorithms.

I'd suggest you to use gzip and gunzip only. For instance, if you generated a backup named mybackup.sql, you can gzip it with:

gzip mybackup.sql

It will generate a file named mybackup.sql.gz. Then, to restore, you can use:

gunzip -c mybackup.sql.gz | psql -U postgres

Also, I'd suggest you to avoid using pgAdmin to do the dump. Not that it can't do, it is just that you can't automatize it, you can easily use pg_dumpall the same way:

pg_dumpall -U postgres -f mybackup.sql

You can either dump and compress without intermediate files using pipe:

pg_dumpall -U postgres | gzip -c > mybackup.sql.gz

BTW, I'd really suggest you avoiding pg_dumpall and use pg_dump with custom format for each database, as with that you already get the result compressed and easier to use latter. But pg_dumpall is ok for small databases.

Sign up to request clarification or add additional context in comments.

2 Comments

@Shadin @MetheusOl I have tried all suggestions above but still an error. gzip: /users/srv-postgresql/backup/bmipgsqld1-testdb-2016-05-31-23-00-05.psql.gz: Permission denied
@kjosh: your problem is permission on the OS for the user you are running the backup. I suggest create a new question if you want more help on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.