I just finished transferring a Ruby on Rails web site from one server to another and also transferring the data from MYSQL to sqlite. I solved all the problems with some help from Pat, and learned along the way.
The first problem was with my deployment using capistrano. Setting up the git repository, pushing it up–that was easy. For some reason my deployments were not working. Git pushes and pulls worked, and I could log into the server via ssh just fine. And when I did log in via ssh, I had to type my password. So I figured that my ssh public/private keys were not uploaded to the server. So I asked my server admin to update my ssh keys, and I emailed him the contents of my .ssh dir so he could dump them in my remote home dir.
This still did not resolve the problem.
Here is what my cap deploy would result in:
[76.73.15.5] executing command
** [76.73.15.5 :: err] Permission denied, please try again.
** [76.73.15.5 :: err] Permission denied, please try again.
** [76.73.15.5 :: err] Permission denied (publickey,password).
** fatal: The remote end hung up unexpectedly
command finished
*** [deploy:update_code] rolling back
* executing “rm -rf /home/andrew/apps/kpmstaffing/releases/20091207060339; true”
servers: ["76.73.15.5"]
[76.73.15.5] executing command
command finished
failed: “sh -c ‘git clone -q ssh://andrew@76.73.15.5/home/andrew/git/kpmstaffing /home/andrew/apps/kpmstaffing/releases
so after a while of fumbling around on my part, and expert looking and inspecting from my server admin, it was found that the problem was with my .ssh/* contents, something was wrong with those files and it was preventing my capistrano to deploy properly via ssh. So, the solution was some expert use of ssh-copy-id on the remote server. Or you could just resend your .ssh public/private keys somehow if you have this problem.
So now my cap deploy would work. The next step was to transfer the database from the live Web site to the new location.
This proved to be quite a task, even though I have done this before and I thought it was going to be easy. Well, there turned out to be some variables that I did not encounter before.
First rudiment, you have to have this file: backup.rake. I dont know where to get it from, I just had it from a project I worked on with a friend.
First thing I did was get a copy of the yml file that was automatically being made daily and sent to an email account that I have set up. I copied this file to my local computer.
Now, I also, just for fun, ran this command on the live web site:
rake db:backup:write
that created another yml file in db/backup/ on the remote server.
So now I had the auto backup yml file, and I could also make a backup yml file of the database any time I wanted. Now what?
Well, I was transferring from mysql to sqlite. So mysql wasnt a problem area because when I did the db:backup:write it just dumped all the data to a yml file in db/backup/. No problem. But on the new location of my web app, it is a bit different because you have to set up a shared db for sqlite. So first thing you have to do is alter your database.yml file to look like this in production:
production:
adapter: sqlite3
database: /home/andrew/apps/kpmstaffing/shared/db/production.sqlite3
pool: 5
timeout: 5000
Then, you have to do a cap deploy:migrate from the local computer, that puts some version of the database there, just something but its not your end product. BUT it should be the correct schema, just the data is not up to date.
Then you have to load the data in there, so get your latest backup yml file, and dump it into db/backup/ on the remote server into the correct version of the app. If you are using git then you will know what I’m talking about here.
now run these commands on the remote server:
rake db:migrate:reset RAILS_ENV=’production’
rake db:restore RAILS_ENV=’production’
That should put the data into the new shared db location. The db:restore command uses the latest file in db/backup/ and dumps data into the database.
Now, if you want to test it, run this on remote server:
./script/server -p 3001 -e production
Use whatever port you want to use, but definitely use ‘-e production’ or your test run will use the development database.
Now for some reason, I had some instructions from before to run this command to load the data into the tables:
rake db:backup:read RAILS_ENV=’production’
That ALWAYS failed and gave me this error:
rake aborted!
Don’t know how to build task ‘db:backup:read’
And I was stuck on this for a while. Finally I opened up backup.rake in lib/tasks/ to see how this file worked, and I noticed that there was no backup:read command, just “restore”. So I changed it to db:restore RAILS_ENV=’production’ and it worked.
So now my website is running. Thanks Pat for the help.
Posted by andrewdegenhardt
Posted by andrewdegenhardt
Posted by andrewdegenhardt 
