Hi, I want to create an administration panel in the application that
would allow to backup the database and some other stuff. How can I
create a backup and send it to some place (s3, ftp) or download it as
a file to the local computer.
Daniel
Hi, I want to create an administration panel in the application that
would allow to backup the database and some other stuff. How can I
create a backup and send it to some place (s3, ftp) or download it as
a file to the local computer.
Daniel
On 6 September 2010 10:25, Daniel M. [email protected]
wrote:
Hi, I want to create an administration panel in the application that
would allow to backup the database and some other stuff. How can I
create a backup and send it to some place (s3, ftp) or download it as
a file to the local computer.
I guess it will depend on your database. This is the code for a
backup action in my app. I wrote it some time ago when I had little
experience so it may well not be the best way.
def backup
# get database name from one of the models
# there must be a better way of doing this
dbname = Act.configurations[RAILS_ENV][‘database’]
if dbname
# delete backup files created on previous backup actions
Dir.glob(“#{dbname}*.sql").each { |f| File.delete(f) }
filename = "#{dbname}” + Time.new.strftime(‘%Y%m%d_%H%M%S’) +
‘.sql’
@answer = system “mysqldump -u xxxxx -pxxxxx #{dbname} >
#{filename}”
if @answer
send_file “#{filename}”
# note cannot delete the file here as the file is sent in
-background
else
# dump failed
flash[:error] = “Mysql dump failed”
redirect_to :action => :index
end
end
end
Colin
Daniel M. wrote:
The project is on heroku and PostgreSQL is used there. I also use
PostgreSQL on my local. I thing creating/editing/deleting files on
heroku is forbidden
It is. But Heroku already provides Rake tasks to back up the DB.
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
The project is on heroku and PostgreSQL is used there. I also use
PostgreSQL on my local. I thing creating/editing/deleting files on
heroku is forbidden
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs