-1

I'm very new to Ubuntu and my first task is to copy one website with a MySQL database to another server. Both servers are virtual machines and in the same environment. I have both the IP addresses and login credentials.

I can sign in remotely from my Windows computer to both machines of course (old server has Ubuntu 10.10 , new server has Ubuntu 12.04).

Now I need to know if i can either copy directly from one Ubuntu server to another or first to my computer and then to the other Ubuntu server.

Or are there maybe many solutions?

slm
  • 7,615
  • 16
  • 56
  • 76
RayofCommand
  • 1,451
  • 8
  • 26
  • 36
  • In posting my answer, I find I need a bit more information on your setup. Firstly there's multiple dialects of SQL - I've covered mysql (and I believe its derivatives) and postgres. This would be very different for other databases. Likewise configuration of webservers varies wildly, especially taking into account scripting languages. I've posted a generic answer but if you could add this in, I can improve my answer further. – Journeyman Geek Aug 09 '13 at 11:15
  • This is non trivial and requires way more information than you have provided. YOu should take a look at http://www.rackspace.com/knowledge_center/article/migrating-a-linux-server-from-the-command-line-stage-1 it and it's associated scripts may help you. – user9517 Aug 09 '13 at 11:17
  • i don't know why you guys downvote this.... – RayofCommand Aug 09 '13 at 13:19

3 Answers3

6

Firstly, one dosen't simply walk into mordor, I mean copy databases. You need to do this right. You'll want to make sure there's no ongoing writes, then make sure everything is copied in a ACID manner. You could shut down the database, move it, then get hit with the realisation things went horribly wrong cause they're different versions...

Luckily mysql comes with a tool to do this called mysqldump - and there's a question on SO on using it with lots of syntax examples - It should be something like mysql -u<user> -p < db_backup.dump. I would also recommend checking the versions since you may need to run an upgrade script between versions. Move the DUMP file, don't copy the database. Run the dump, run the upgrade script, test. As you can tell, Mysql has good resources on it, so read up and make sure you know what you're doing.

If you're using postgres, there's also pg_dump (which has an oh so elegant syntax). And its file level backup documentation is true anywhere - since shutting down a server is the surest way to not have writes while you're backing up, mucking up consistancy.

To move the dump file while there's quite a few methods SFTP is probably the ideal combination of speed and security. You can transfer files computer to computer with pscp or download them to your windows system, then reupload them with cyberduck. Since you already have SSH, this should be the simplest way to do this.

Web server configuration, and files (IE, the effective contents of /etc/ and /var/www) should be alright to copy, since they arn't constantly being changed.

Journeyman Geek
  • 6,977
  • 3
  • 32
  • 50
1

You can use scp or rsync for sending files/directories between your Ubuntu servers directly.

e.g.:

scp -r /local_dir/path user@otherhost:/remote_dir/path

Databases can be migrated by using the backup/dump and restore functionality that's typically provided by your DB server software (MySQL, Postegres, etc.). The exact process depends on your database server.

1

You can use rsync for this,
Example,

we are assuming that you have ssh access to both server's, old.com is for old one, and the uname is the same on both servers and the file tree to copy is /var/somedir login to the new server,


rsync -av user@old.com:/var/somedir/* /var/somedir/ 

It will login to old.com and prompt for authentication, then build a file list and copy the content to the target on the current server.


I hope you understand this...
Thank you
Radhe
  • 339
  • 1
  • 2
  • 10
  • rsync probably is a better choice for file transfers than sftp or scp as I suggested in my answer - especially if you're moving large files. – Journeyman Geek Aug 09 '13 at 12:52