May 05

Moving a website from one server to another (the command cheat sheet)

Category: Linux   — Published by goeszen on May 5, 2012 at 12:41 pm

This here is a simple cheat sheet of CLI commands to move or migrate directories and sql databases from one machine to another:

Dump a database table from MySQL:
$ mysqldump -u <db-username> -<db-password> --opt --quote-names --allow-keywords --complete-insert <db-name> <db-table> > <output-file>

Slurp a database table back into MySQL:
$ mysql -u <db-username> --password=<db-password> -D <db-name> < <input-file>

Copy over a MySQL table dump or any other file
$ scp -P <optional-port> <username>@<IP>:/some/path/to/remote/file <local-file>

Copy over a complete directory with rsync, with additional ssh parameters:
(more elabnorate with bandwith limit etc in: scp but keep existing files, then use rsync)
$ rsync -av --progress --stats --copy-links -e 'ssh -p <ssh-port>' <username>@<IP>:/path/to/dir/with/trailing/slash/ /path/to/target/dir

Tar a directory (more in Move a complete directory from one server to another):
$ tar -cvf archive.tar . && gzip archive.tar

Tar a directory and then 7zip it (instead of gzip):
$ tar -cvf archive.tar <source-directory> && 7zip a <input-tar> <output>.tar.7z

Tar a directory and 7zip zip it in one go (from tar a file or directory and 7zip it in one go):
$ tar cf - <path or file> | 7zr a -si <output>.tar.7z
 

Leave a Reply

=