Copying Multiple Files using SCP

by cliper Thursday, January 20, 2011 10:43 AM

 

For the rest of my Linux experience, I've been doing a lot of backups. One tool that I can rely on is "scp" (Secure Copy).

Well, I'd recommend this tool when copying files from server or vise-versa.

Here's the how to use it:

 

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]

           [-l limit] [-o ssh_option] [-P port] [-S program]

           [[user@]host1:]file1 ... [[user@]host2:]file2

 

In this snippet, we only need the "user@host1:]file1

There are also popular tools like rsync, wget, or version controls like git, etc... when downloading files, synching projects etc. and I will post about it later.

Anyways, here's my code snippets for scp:

"For this snippets, suppose we have a server named "google-server.com" and we had files named twitter.txt and facebook.txt under /home/cliper/"

Copy (download) multiple files: twitter.txt, facebook.txt from google-server.com

// note, we use brackets together with a back-slash to separate multiple files.
scp user@google-server.com:/home/cliper/\{twitter.txt,facebook.txt\}

 

 

Copy (download) twitter.txt from google-server.com

scp user@google-server.com:/home/cliper/twitter.txt

Uploading files to the server is much like the command above. In the following examples, we have server1.com as our target server and we have a folder /home/cliper/ there. Assumed that we had a Linux box locally when sending the files to server1.com. Now take a look at the difference. So if we have /home/mylocal_linux_pc/file.txt you will do something like..

Upload files to server1.com

 

scp /home/mylocal_linux_pc/file.txt user@server1.com:/home/cliper/

 

 

Tags: ,

Code Snippets | Linux

Backup/Restore mysql databases using mysqldump

by cliper Wednesday, December 08, 2010 12:35 PM

Sometimes we want to have a dump of all our databases in mysql and restore it later to somewhere else or in the same server. here’s how...

In your terminal:

Backup database...

 

mysqldump -uuser -ppassword database_name>database_name.sql

 

where user is your mysql db user, and password. Note: No spaces should be inserted after -u and -p. Specially in -p for password.

To restore database...

 

mysql -uuser -ppassword database_name<database_name.sql

 

while we can do the above command for restoring. We can also do it safely by using the source keyword in mysql.

In terminal, do:

 

mysql -uuser -ppassword

 

 

When in mysql console, execute:

 

USE database_name;
SOURCE database_name.sql;

 

Make sure you change to the path of the file database_name.sql where it resides. Otherwise, you will get an error similar to: Failed to open file 'database_name.sql', error: 2

Also, we can back-up a table instead of the whole db.. you can do:

 

mysqldump -uuser -ppassword database_name table_name>database_name.sql

 

 

and should be able to restore it too.

 

Tags: ,

Code Snippets | Linux | MySQL | Tips/Tricks

Excluding files and folders with tar

by cliper Wednesday, December 08, 2010 9:24 AM

Excluding files/folders using tar is very straight forward.

Assuming we have a directory tree similar to this in Linux

-/home/cliper/
            |--- folder/
                     |--- file1
                     |--- file2
                     |--- folder

and we want to exclude file2 and folder to the archive, then command would be like:

tar –czpf filename.tgz --exclude=/home/cliper/folder/file2 --exclude=/home/cliper/folder/folder

Get Magento’s database configuration

by cliper Tuesday, December 07, 2010 5:58 PM

On Linux, make a php file anywhere in your filesystem while including the magento Mage file.

<?php

require_once "/home/cliper/magento/app/Mage.php";

Mage::app();

$config  = Mage::getConfig()->getResourceConnectionConfig("default_setup");

$dbinfo = array(“host” => $config->host,
                “user” => $config->username,
                “pass” => $config->password,
                “dbname” => $config->dbname
);
?>

 

 

where /home/cliper/magento/ is your magento absolute path.

In windows, change the directory like:

require_once “C:\magento\path\app\Mage.php”;

You can then use the array like:

echo $dbinfo[“host”];

 

Tags: ,

Code Snippets | Magento | PHP | Tips/Tricks

Rebuilt Magento Indexes in terminal with php-cli

by cliper Tuesday, December 07, 2010 5:25 PM

 

For the past 6 months, had been doing a lot of work with Magento. I’ve notice that the more I know the whole thing, the more I don’t want to share about it. Well, I still like to share some things though… so now it’s time to give some tips/tricks…

In your terminal do:

cd /magento/shop/path/shell/

where “/magento/shop/path” is your magento rooth path. For e.g. (in live terminal)

user:~$ cd /home/cliper/magento/shell/

after that, you can run the indexer by doing:

php indexer.php reindexall

that will re-index all available indexes in magento.

Well, you can always run it in one command like:

php /home/cliper/magento/shell/indexer.php reindexall

For help on how to use the indexer and available arguments do:

php indexer.php

For a list of available indexes do:

php indexer.php info

and you should be able to see a list of indexes something like this:

catalog_product_attribute     Product Attributes

catalog_product_price         Product Prices

...                           ...

 

 

About the author

Author's PhotoI enjoy web developing and would like to share my thoughts of it.

Send mailE-mail me

Most comments

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar