Vital Command Line Tools for Linux Server Migration

27 Apr 2009
Posted by editor

Here is a crib sheet for the most common and useful commands needed when migrating or backing up a linux server. Thes tools make the work easy and fast. The trouble is that unless you are backing-up manually or migrating servers for a living, must of us only have to deal with these commands occasionally and the exact usage becomes a little hazy over time. below are the basic usage details of tar, wget,mysql and mysqldump ...

TAR

Use tar to compress directories, sites, even the whole file system if you want. It is very handly for backups and site migration.

Use it to compress like this ...

tar -cjvf your-backup-file.tar.bz2 ./directory-to-copy

If you intend to move the file to another server then it is best to point the location of the compressed file to a place where it is publically available through html; Then you can use wget to fetch it.

Use tar  to de-compress the file like this ...

tar -xjf your-backup-file.tar.bz2

 

WGET

This is a very powerful command that has many uses. One is to retrieve publically accessible files quickly. In the above tar example, lets assume we have placed our compressed file in the root of http://www.mydomain.com. You can now fetch it using the following command ...

wget -c http://www.mydomain.com/your-backup-file.tar.bz2

Because your files are compressed and this method is generally far quicker than ftp, most transfers take moments. If you are transferring between servers the transfer rate is often above 1MB/s.

 

MYSQL & MYSQLDUMP

Use mysqldump to backup your databases

mysqldump -u yourusername -p yourdatabasename > your-database-backup.sql

You will be prompted for the password that matched the sqluser. To restore your database, make sure that the stated database exists and then run the following with your backup file ...

mysql -u username -p databasename < your-database-backup.sql

 

Trackback URL for this post:

http://www.zygmund.net/trackback/31