Heroku Rails Console Console for Local File

I want to extract some information from my database into a text file.

What a good way to do this? Initially, I was thinking of starting mykkku bash and rails console, since I just need to do a simple loop to get the information I need. But I do not know how to write a file from a hero. It works in my local rails console

I tried

File.open('text.txt', 'w') do |f| User.all.each do |u| f.puts u.email end end 

or something like $stdout = File.new('/path/to/text.txt', 'w')

but I think these files do not fall into my local directory ...

How to do it?

Alternative simple solutions are also welcome, as I did not think that I was doing something too complicated

Trying to answer Pakrash

In heroku bash + rails c

I put

  require 'net/ftp' ftp = Net::FTP.new('address.herokuapp.com',' email@example.com ', 'somepassword') 

It just freezes. There is no mistake. I need crl + c from her

I previously had my full address https://adddress.herokuapp.com/ , but he said getaddrinfo: Name or service not known

Should I introduce this differently?

+6
source share
3 answers

Heroku supports ftp in passive mode. Therefore, create a file on the server and upload the file to the local computer with ftp.

 # FTPing from Heroku ftp = Net::FTP.new(server, user, pass) ftp.passive = true ftp.getbinaryfile(remote_filename, tmp_filename) 

References:

+2
source

Pervertedly, I found it easiest to just email the content to myself.

+2
source

I do not know if this is appropriate, but you can actually run the rails console instance locally when connected to a remote Heroku database. Get the database connection information from the Heroku toolbar and add it to your local database.yml file instead of your usual development stanza. Sort of

 development: adapter: postgresql encoding: unicode database: agblah9dff3 host: ec2-44-333-444-100.compute-1.amazonaws.com pool: 5 username: 8fk38hg72hd98d port: 5462 password: 88dk3jblahblah8sk83df8sdfj23 timeout: 5000 

But know that you play with production code, so ... you know, it's pretty risky.

A better idea would be to simply use an IDE database that creates an export for you, or write a rake task that collects information in a file and uploads it to S3. You cannot write files to a Heroku disc.

+1
source

Source: https://habr.com/ru/post/981528/


All Articles