Heroku automatic db backup via cron job - ruby-on-rails

Is it possible to backup Heroku database using cron jobs?
I tried putting the following line into cron.rake:
heroku pgbackups:capture --expire
However it didn't work. The line works when I run it from Terminal.
Can you help?

Check out the heroku_s3_backup gem, which packages up the code necessary to do this in a neat way.

The gem heroku_backup_task integrates directly with the free PG Backups add-on for Heroku.

Related

Heroku CLI throws an error whenever I try to do anything: "Please specify a version along with Heroku's API MIME type"

As of this morning, without having change anything in my Heroku CLI setup, I received the following error when I tried to run:
heroku logs -t -app <app_name>
! Please specify a version along with Heroku's API MIME type. For example, Accept: application/vnd.heroku+json; version=3.
I have since tried updating both heroku and heroku-toolbelt via brew upgrade heroku and brew upgrade heroku-toolbelt, but this did not solve the issue.
I get this error essentially whenever I try to do anything with heroku CLI, including heroku logs, heroku apps, heroku login, and heroku auth:login.
I am running MacOS, and the error posted is the only information that I am getting back from Heroku.
This discussion here: How can I specify heroku's MIME type? pertains to upgrading Heroku in Ubuntu and does not solve my issue.
I had the same problem -- but installing the new Toolbelt did not work at first. There was one other step I needed to do.
from: https://devcenter.heroku.com/articles/heroku-cli
It has instructions for each platform on installing the new cli -- and says you need to run: which heroku in order to verify the proper version is running. In my case I also needed to do a gem uninstall heroku in order to get everything working, as it was running the gem binary instead of the newly installed heroku-cli binary.
If you were using heroko Plugin for intellij
I tried alot to make it work !
From here official response
#emzeidan thanks for the report. This plugin is deprecated, and uses an old version of the Heroku API that has been shut down. Please recommend to your users that they use one of the alternative deployment mechanisms described in our DevCenter article on WAR deployment. If you can remove from the plugin from any Bamboo marketplace (or similar thing) that would be helpful too. Thanks.
This was on Sept-2017
I run the 'heroku --version' command and the toolbelt automatically updates the client. After that the login was ok.
I had the same problem on macOS Sierra 10.12.3 when I installed heroku via brew.
To get round it I ran brew uninstall heroku-toolbelt then installed via the Mac installer at https://devcenter.heroku.com/articles/heroku-cli#macos and it works fine now.
Have you specified the heroku gem in your Gemfile? If yes, then remove it.
And then, install Heroku CLI for https://devcenter.heroku.com/articles/getting-started-with-ruby#set-up and run your command.

Heroku : This version of the API has been Sunset. is displayed when heroku pg:psql

When I try to use heroku pg:psql, the following error is displayed.
! This version of the API has been Sunset.
! Please see https://devcenter.heroku.com/changelog-items/1147 for more information.
How can I access postgresql on Heroku?
heroku pg:psql command worked a few week ago.
I develop my Rails app on the Cloud 9.
I had the same issue with my ruby on rails project since last Friday.
However, i was able to resolve this error message by update my heroku toolbelt on my mac os.
*Hint, if your heroku file was installed in project gem. you will need to delete that file.
Use command which heroku to identify where is the heroku file. if it is inside the .rvm folder that means your project is still using outdated heroku file. and simply remove it and then ran an new install heroku cli should fix this error.
Let me know if this works for you.

How to have Rails migrations run automatically on Heroku

I have more than 10 different Ruby on Rails apps where I have to deploy the same code. I have connected the git repo to my Heroku apps, so whenever I push new changes it deploys on all of them.
The issue is with the database migration step. I want to run migrations automatically after each deployment. None of custom build pack is working. Can someone please help me? I am using rails 4 and spree.
So far, I have tried:
https://github.com/heroku/heroku-buildpack-ruby.git
https://github.com/gunpowderlabs/buildpack-ruby-db-migrate.git
This solution is not working.
Is there any other solution to run Rails migrations on Heroku automatically?
No need to use gems or write scripts.
Heroku have a 'release' phase features (https://devcenter.heroku.com/articles/release-phase).
Thank to this, you just have to add to your Procfile some code to automatically run rake db:migrate to all your push :
Procfile (root app)
release: rake db:migrate
You can use Travis-ci. Pretty simple to setup and provides the desired functionality
Add gem 'iconv', '~> 1.0.3' to your gemfile and then try it will work as worked for me!
I take this as a duplicate of this answer
If you are looking for alternative then you can write a deploy script in .sh file and run it everytime like bash script.

Rails EC2 Deployment - no such file to load

I'm working against a variety of constraints that are troubling an EC2 Rails deployment. I'm not allowed to use Capistrano because I cannot save this application to any public git repository (like GitHub) and I also need to retain complete control over which instance on EC2 the Rails application is installed to and be able to modify this easily (adding load balancers, auto-scalers, etc.) on the fly from the AWS Console, so I also cannot use Rubber.
I finally resorted to simply ssh'ing my Rails application directory over to the EC2 instance, but am running into a 'no such file to load' error when running bundle install, specifically the Time gem. Because this is an 'integrated' gem, I think I might just be overlooking something simple. Here are the things that I've tried:
I've used RVM to manage my versions of ruby, rails, rubygems, etc.
Deleting my Gemfile.lock file and re-running bundle-install
Including 'Time' in my GemFile and re-running bundle-install
This application runs without issue on my local development environment, so what am I overlooking?
Note: I am REQUIRED to host on a single EC2 instance. Otherwise, I'd simply deploy to EBS, Heroku, etc.
This was a stupid mistake, also detailed in this question: heroku - cant run rake db:migrate - no such file --Time
I incorrectly had a require statement in a controller for 'Time', instead of 'time'. This was allowed locally, but my ubuntu server ruby environment was not as forgiving. Changing the 'T' to a 't' in my controller and running 'bundle install' resolved this issue completely.

Implement capistrano in ruby on rails having database MongoDB

I want to implement capistrano in my ruby on rails project. I am using MongoDB as database .
I install capistrano gem.
capify .
[add] writing './Capfile'
[add] writing './config/deploy.rb'
[done] capified!
It gives me file deploy.rb inside the Config. What should i do inside. so where do i have to put mongoid.yml ? Working code is helpful for me to do or some hints is appreciable.
You should first be clear about why you want to implement capistrano :-)
Capistrano is a tool for making deployments easier - it allows for executing commands in multiple remote machines, via ssh.
For a default installation of a Rails App with mongodb, you don't need to have anything related to mongodb in the capistrano deploy.rb file.
You would add some mongodb stuff in this file if there is some mongodb related task that you want to accomplish every time the code is deployed to the remote servers.
Example: Here is a capistrano recipe example to synchronize local mongodb with production
I would recommend that you familiarize yourself with the basics of capistrano by watching the railscast episode on capistrano tasks.
Put mongoid.yml in /config, and type cap deploy in /.

Resources