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
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
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
Daniel Morigan 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.
Best,