Geek Essential Objectively finite, subjectively infinite.

23Aug/110

scp, another way to copy…

This is somewhat obvious, but when moving files from a server to a server, security should be one concern. So you use scp. It's a simple copy tool that uses SSH to transfer data between two computers.

Simply, it works similarly the way that cp works, except that you need to indicate login credential and remote server name.

So to copy files from remote server to current server, a syntax would look something like ...

#scp remote_user@remote_server:/remote/directory/some_file /local/directory/

And to copy files from local to remote, it would look like ....

#scp /local/directory/somefile remote_user@remote_server:/remote/directory/

You can also use options like -r to copy directories as well.

#scp -r remote_user@remote_server:/remote/directory /local/directory

There are other options you can easily find from man pages...

19Aug/110

moving an entire mysql database…

There comes a time when it is necessary to move servers... and it's related services and databases... it was time for me to move onto bigger and better ... server that is. Over the years, we have tried out and customized few things within the web server which ended up getting big ... in the process mysql database also gotten bit big... so to migrate from one to the other... I had to use the dumpmysql but standard usage of mysql dump resulted in whole bunch of errors including errorno: 24  which was result of large database.

But this can be avoided by using the flag –lock-tables=false into the command line.

$mysqldump --opt -u [user.ID] -p -A --lock-tables=false > [dump.filename]

After that, it was easy as just moving file from one server to another using any secure method you like and using following command to restore it on to the new server...

mysql -u root -p[root_password] [database_name] < dumpfilename.sql

Note: if no database exist in your new server [database_name] can be omitted.

And that's it, your new database is all new and shiny...

Reference: http://jamielesouef.com/linux/tip-backing-up-a-large-mysql-database-errno-24/

18Aug/110

quick rsync how to…

Working in Linux servers sometimes makes it inevitable to use rsync to move and synchronize files from one server to another. This is where rsync excels as it does not only moving of files but also incremental synchronization between two servers. It's also great tool to backup files to a remote server when used in conjunction with cron to automate it. Most new installation may not have it installed on their boxes, in debian it is as easy as typing

apt-get install rsync

to install the latest version.

Once installed you'll need two servers to properly test it. First of all, as you are accessing other server you will need an account on all servers. Also, since rsync doesn't have secure transfer by default, make sure to install open-ssh on both servers to transfer files securely.

Some common options are:

  • --delete : delete files that don't exist on sender (system) (Use with caution!!!)
  • -v : Verbose (try -vv for more detailed information)
  • -e "ssh options" : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data
  • progress: will show the percentage of the file copied

Example commands:

Copy files from local server to remote server

$ rsync -v -e ssh /[local folder]/[local file] [remote.user]@[remote.server]:~
note: ~ indicates home directory of [remote.user]

Copy files from remote server to local server

$ rsync -v -e ssh [remote.user]@[remote.server]:~/[remote.file] /[local.folder]

Synchronize directories from local server to remote server

$ rsync -r -a -v -e "ssh -l [remote.user]" [remote.server]:/[remote.directory]/ /[local]/[directory]

Synchronize directories from remote server to local server

$ rsync -r -a -v -e "ssh -l [remote.user]" [remote.server]:/[remote.directory] /[local]/[directory]

There other features such as excluding files while syncing and mirroring folders. Also, this process can be easier if password less authentication is set up between two servers. However, most of the basic use is covered above.

References:
http://www.cyberciti.biz/tips/linux-use-rsync-transfer-mirror-files-directories.html