8

After establishing a database using heroku addons:create heroku-postgresql:hobby-dev, I tried to migrate my local database to heroku database. So I first ran

heroku python manage.py migrate. After that I created a dump file of my local database using pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump. I uploaded my mydb.dump file to dropbox and then used the following command to load the dump to my heroku database

 heroku pg:backups restore'https://www.dropbox.com/s/xkc8jhav70hgqfd/mydb.dump?' HEROKU_POSTGRESQL_COLOR_URL

But, that throws the following error -

 r004 ---restore---> HEROKU_POSTGRESQL_PURPLE
 [0KRunning... 0.00B..
 [0KAn error occurred and your backup did not finish.
 Please run `heroku pg:backups info r004` for details.

And on running heroku pg:backups info r004 I get -

Database:    BACKUP
Started:     2015-06-25 18:19:37 +0000
Finished:    2015-06-25 18:19:38 +0000
Status:      Failed
Type:        Manual
Backup Size: 0.00B
=== Backup Logs
2015-06-25 18:19:38 +0000: waiting for restore to complete
2015-06-25 18:19:38 +0000: pg_restore: [archiver] did not find magic string in file header
2015-06-25 18:19:38 +0000: restore done
2015-06-25 18:19:38 +0000: waiting for download to complete
2015-06-25 18:19:38 +0000: download done

There is not much information on this error online and I can't figure out what the problem is.

WutWut
  • 1,204
  • 2
  • 17
  • 31
  • how big is the database? – Tommaso Barbugli Jun 25 '15 at 19:32
  • @TommasoBarbugli 7.4mb. I've got a free heroku account. Is the database size too much? – WutWut Jun 25 '15 at 19:50
  • The problem may actually be somewhere completely different: Dropbox is usually not offering the raw file on that link. Instead it is serving a download page. Add a `?raw=1` to the end of the URL to retrieve the raw file and use with heroku pg:backups. – Jelko Aug 02 '16 at 14:29

4 Answers4

21

If the database is small and you feel lucky this might do it

pg_dump --no-acl --no-owner -h localhost -U myuser myd | heroku pg:psql
Tommaso Barbugli
  • 11,781
  • 2
  • 42
  • 41
9

I've had this error too and my solution was a little different. The problem was related to the format used. I needed to use --format=c when dumping the db.

To solve it I dumped the db again using --format=c

pg_dump --no-acl --no-owner --format=c database_name > db.dump

Then importing it to my heroku app

heroku pg:backups restore 'url_for_db.dump' DATABASE_URL

Hope this helps someone in the future!

1

You can use : heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi

source: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push

Dinatih
  • 2,456
  • 1
  • 21
  • 21
1

For windows users;

heroku pg:backups:restore "https://s3.amazonaws.com/me/items/3H0q/mydb.dump" DATABASE_URL

According to the official docs, be sure to use double-quotes around the remote url if you're using windows. see official docs

shaded
  • 89
  • 1
  • 6