Can I import .dump file to heroku through travis - heroku

I am having a QA instance which contains a very limited data(approx 30-35 MB) it contains images etc, thumbnails hence cannot put them into seed.
I have a private repo at github(synced with heroku) which contains a .dump file say abc.dump file and I want to run my test cases from travis, in the before script I will be restoring this dump.
I would like to know how to import this dump to heroku although this is available at heroku bash as well. I looked into the documentation here they say make it asseccible through http somewhere. I am trying using the pg_restore commands using the database username, passwords available at the application database overview available through UI, but not working.
Can someone suggest me a good way out to simply restore by not making my database public ?
Also. how often the database user/password is changed at heroku ?

As travis would be having access to abc.dump beforehand it can perform basic pg_restore function of postgresql.
PGPASSWORD=<PASSWORD> pg_restore --verbose --clean --no-acl --no-owner -h <PG_HOSTNAME> -U <PG_USER> -d <PG_DATABASE_NAME> -p <PG_PORT_NO> <DUMP_FILE>.dump
The above details for the heroku database hostname, user, pass, port etc. can be fount easily using :-
heroku pg:credentials DATABASE --app application_name

Related

Forgot to migrate free tier Postgres and now my app is empty

My project is again live no problems whatsoever, but the database is empty.
I am either trying to restore an old backup to the new Postgres instance or upload a backup from my local disk.
I tried to do pg:restore but I don’t know where to grab the backup (from the free Heroku tier).
I got the answer I was looking for by going into some of the most hidden help articles in heroku.
https://help.heroku.com/QG1W7LIJ/how-do-i-restore-a-partial-backup-or-single-table-to-heroku-postgres
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U YOUR_USERNAME-d CONNECTION_URL mydb.dump
Had to recreate the backup from the local imported database but at the end it worked flawlessly.

Need help understanding Importing Heroku Postgres Databases with PG Backups

I'm reading the documentation here, and I have a few questions. Just to make sure I'm not misunderstanding what this terminal command is supposed to do.
Question 1:
I have an SQLite .db file on my local computer. With this command, I can convert this db into a mydb.dump file, which I can then import into Heroku Postgres. Is this intepretation correct? If so, we can move on to my second question.
Question 2:
Attempting to run PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump is causing me some issues. From what I can understand, the values I'm supposed to substitute are
mypassword (heroku postgres password)
myuser (I have no idea what's supposed to be here)
mydb (name of db)
mydb.dump (name of dump)
What exactly should go into each of these values, and where can I find them?
The pg_dump command dumps a PostgreSQL database. It has nothing to do with SQLite.
SQLite and PostgreSQL are very different databases. If you're going to use Postgres in production I strongly recommend using it in development as well. In general, your development environment (and any others, like a staging environment) should be as similar as possible to your production environment.

Trying to pull Heroku database onto my localhost

I recently made a mistake by rolling back my database too far on my localhost and removed all the data from within the databases I've had. I did migrate the databases so they would return but they still were cleaned out.
Asking around what to do next, I was told that I should backup the database on Heroku (which has all the current information) and pull it onto my localhost. If this is the correct action to take, then I am still facing a problem. When I type:
heroku pg:pull DATABASE_URL mylocaldb --app (my_app_name) it returns an error of:
sh: createdb: command not found
!
! Unable to create new local database. Ensure your local Postgres is
working and try again.
I do not have the best understanding of databases as I am newer; however, I have downloaded sql on my local machine. All of the commands I input are in the regular console and not the psql terminal.
If anyone has any knowledge or can help me, I would greatly appreciate it. Thank you so much!
Joe
Edit: If you do have another method/solution, please let me know. I cannot update my application until I have this done so I do not lose my information.
I would try using backup/restore:
heroku pg:backups --app MYAPPNAME capture
curl -o latest.dump `heroku pg:backups --app MYAPPNAME public-url`
as (almost) documented at
https://devcenter.heroku.com/articles/heroku-postgres-import-export
Note the strange placement of --app MYAPPNAME. It needs to go immediately after the heroku sub-command and before any other arguments.

Heroku mysqldump to remote host

I created a nice little Rake task to backup our Mysql database on ClearDB to a remote Google storage bucket. Works great locally but running it on Heroku I get this error:
sh: mysqldump: not found
Of course, Heroku doesn't have mysqldump, how silly of me, but is there any way to do this?
The command I'm using is something like this:
system "mysqldump -h host.cleardb.com -u user -p'password' --single-transaction database | gz > #{backup_directory}/#{file_name}"
Of course gzip doesn't exist either on Heroku.
I know there are a couple of gems to backup PostgreSQL databases but I haven't seen anything for Mysql.
This is for a Rails 3.2 app.
Any ideas would be appreciated.
I'd say your best option would be a custom build pack that adds the mysql binaries that you need.
https://devcenter.heroku.com/articles/buildpacks

Heroku app change: db migration (pg and MongoHQ)

I had and app on heroku
then I decided to create another app (on cedar stack which does not support stack:migrate).
How can I migrate databases PG and MongoHq?
Thanks!
You can migrate MongoHQ by logging into heroku and clicking on addons => mongohq. From the application, create a new user under Database Users named "backup" with a simple password. Below, my password was "temppw". Then click the Database Info tab for your connection information (host:port [flame.mongohq.com:27049] and dbname [appXXXXXX]). Then just call mongodump to get a backup.
mongodump -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw
This will make a local directory called "dump" containing your data. Verify it is there by loading it into a local db (just run mongorestore and look in your local mongo install) - because when you destroy your old app, it destroys the MongoDB (heroku also destroys your postgres db - so you should do this for that as well).
Anyway, do the same as above to your new application database, except use mongorestore.
mongorestore -h flame.mongohq.com:27049 -d appXXXXXX -u backup -p temppw dump/appXXXXXX
DO NOT JUST POINT THE ENVIRONMENT URLS. This is dangerous, because deleting your initial app will destroy all of your data.
I'm not sure about MongoHQ but as for PostgreSQL, you can use Heroku Taps to pull the data from the remote database to your local machine. You could then push it to the new app.
Alternatively you could change the environment variable DATABASE_URL of your new Cedar app to point to the database being used by the old app - assuming you're not using the shared database.
This last approach would also work for MongoHq.

Resources