I have a Rails 3 development environment that I need to move to another machine. I would like to know 开发者_StackOverflow社区the best way to move the application code, mysql database, and gems with the least amount of disruption?
In development:
- Make sure Ruby version is the same. Copy all gems.
- Copy application
- Make dump of database and load it to new DB. If DB is exactly same version and OS as well copying binary data files may be enough.
In production the worst part is syncing DB and DNS.
- If you can lower TTL (to 1 hour) on DNS entry of your domain - to have DNS propagation respond better.
- Wait previous TTL + new TTL to be sure all clients and proxies updated - in a meantime you can prepare Rails 3 app on new machine.
- Setup TCP/IP forwarding on new machine 80 port to old machine 80 port, with exception for your workstation (to have access to app instance on new machine).
- Finish preparing app, gems, with copy of db, test it.
- If everything is ok, change DNS A entry to new host IP - in this case within 1 hour all clients will be connecting to old instance via new one (forwarding). Wait 1 hour.
- Now offline: Stop old instance with maintenance message
- Make db dump and load it on new instance
- Restart new app instance
- Turn off forwarding. End of offline.
Are you using a revision control system such as git or svn? If yes then you simply need to checkout your code onto the new machine. If no, then I wouldn't do anything until you get it into git / svn / your revision control software of choice.
Gems should be taken care of by bundler. Just run bundle install
inside the source directory on your new machine once the source code has been moved over.
To move the database you can either rebuild it from scratch if you don't have any important data with rake db:create db:migrate
. Otherwise use mysqldump database_name > database_name.sql
to dump your database to an SQL file which you can import on the new machine (cat database_name.sql | mysql new_database_name
).
精彩评论