views:

541

answers:

8

Hello.

I've inherited a Ruby on Rails application that has a problem. I'm half way through some books on Rails, but haven't seen the answer to some questions yet.

  1. What is the best way to backup the application? Can I just tar -cvzf app.tgz app? I don't know yet if the app has a sqlite3 database or connects to a db server.

  2. What's the best way to move the application to another server for testing? Again, I don't know if it's sqlite3 or a db server backing it.

Thanks,

Michael

Update: Yes, I will be using version control. There isn't any right now. The question I think I was trying to get at is: how transportable is the app directory; if I want to move the entire application to another computer do I need to take anything else along with me?

A: 

For both, I would suggest a version management system. Perhaps Subversion

That's what I did, for similar reasons.

If you look into the database settings in config/database.yml, you'll find whatever database is being used. If it's sqlite, just make sure it's part of the subversion repository.

Beyond that, when you do an export or a checkout on the other server, just make sure that server has access to the database, wherever it is.

Be more specific where the "database settings" are. He is a noob afterall.
Ryan Bigg
A: 

Version control should be a good start. You should immediately find out what is the backing database and make sure that you not only have 1 database file/server around, but a second instance for testing. Don't mess around with production data.

siz
A: 

To "backup" the code for the application you can use git with http://github.com. This gives you an offsite area where you can put your code, but I think you have to pay for the private repositories (around $12/month). Alternatively, just set up a git server on another box in your office and host it there.

The "database settings" are kept in config/database.yml and this will tell you the information you need to know about the database.

Ryan Bigg
+2  A: 

I would have a look at Capistrano - this is the deployment/management tool of choice.

At it's core, it will grab your application from source control, deploy and configure the destination server, and run any database migrations.

You can use it to point to multiple servers (such as test, staging and production).

To answer your actual question, you can move your app by simply copying the Rails directory (note: not just the app directory, but the parent directory as well). Your database will need to be managed separately - in the case of sqlite, you can just grab the files, if you are using MySQL you would probably dump the database and reconfigure on the next server.

Toby Hede
+1  A: 

I don't know yet if the app has a sqlite3 database or connects to a db server.

Look at the database.yml file in the config directory. The adaptor line will tell you what DB it's using.

Mick T
A: 

GIT (or SVN) + Capistrano for code, for data there are options:

  • There are several rails plugins for dumping your application database and assets. My favorite is github.com/toy/dump. You can run rake dump:create and rake dump:restore. The most exciting is capistrano integration — cap dump:mirror:down downloads application assets and database, it creates a clone of your site on local machine.

  • If you need automatic backup of your application to sleep well, I would recommend you Backup My App service. This is complete solution for automatic backup of rails applications, you just need to install their plugin and they handle the rest of the process automatically. They keep the history of your backups for several weeks, you can explore them via browser and restore automatically any of them.

Igor
+2  A: 

A good way to back up code I've found is to use git and push to a bare repository that's stored on Dropbox (http://getdropbox.com)

The workflow is something like this (assuming Unix-based system like OSX, if Windows, adjust paths accordingly)

Create the local app and make a git repo from it:

cd ~/Rails
rails my_app
cd my_app
git init
git add .
git commit -m "first commit"

Then on your Dropbox directory, make a bare repository (I used a directory called 'git' under it)

cd ~/Dropbox/git
mkdir my_app.git
cd my_app.git
git init --bare

Now go back to you application and add Dropbox as an origin and push to it

cd ~/Rails/my_app
git remote add origin ~/Dropbox/git/my_app.git
git push origin master

After you make changes in your ~/Rails directory, just push to the dropbox repo and it will be backed up on thier severs (and you can easily share the repo on all machines you have linked up to Dropbox)

Dan McNevin
+1  A: 

You can just copy the whole directory. However, it is common practice to 'freeze' your Rails install and your gems into the directory first, if this hasn't already been done. This ensures that the testing server you copy the app too has and uses the exact same version of Rails and any gems installed.

If this has been done, you should have a vendor/rails/ directory.

You can 'freeze' your Rails by running:

rake rails:freeze:gems

You'll also want to make sure Ruby is the same or a similar version on both hosts. I've had trouble with 1.8.7 vs 1.9.1 - keep it in mind.

nfm