Posts Tagged ‘ssh’

Change ssh login folder

Tuesday, January 10th, 2012

After you ssh into server:
$ vi /etc/passwd

You should see something similar to
bloom:x:502:503::/var/www/vhosts:/bin/bash
devuser:x:48:505::/home/devuser:/bin/bash
bloomcom:x:503:506::/var/www/vhosts:/bin/bash

Just change the part where is says: /var/www/vhosts
to whatever folder you want

Get the current size of your hard drives

Saturday, January 7th, 2012
$ df -h ( hit enter )

Will return something similar to:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5             128G   80G   47G  64% /
/dev/sda2             2.0G  264M  1.6G  15% /tmp
/dev/sda1              99M   23M   71M  25% /boot
tmpfs                  16G     0   16G   0% /dev/shm

Command Line – copy files using rsync

Friday, August 5th, 2011

rsync is a software application for Unix and Windows systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction. rsync can copy or display directory contents and copy files, optionally using compression and recursion.

In daemon mode, rsync listens on the default TCP port of 873, serving files in the native rsync protocol or via a remote shell such as RSH or SSH. In the latter case, the rsync client executable must be installed on both the local and the remote host.

I use rsync a lot specially to backup my important files between two computers, but also to keep my local slackware repository up to date.

rsync is great to keep folders and files synchronized between two computers or in the same computer, you can backup all your important data to an external disk using rsync.
rsync uses
Copy files with rsync

From local to remote computer

rsync –progress –partial -avz /folder/to/copy/ user@remote.server:/remote/folder

This will copy all files in /folder/to/copy/ to /remote/folder in the remote server, the folder copy itself will not be created in the remote computer, and only its contents will be copied, if you want the folder itself to also be created and then its contents copied inside the newly created copy folder, use this command.

rsync –progress –partial -avz /folder/to/copy user@remote.server:/remote/folder

Note the trailing slash after copy that makes the difference. The rest of options are:

progress: will show the percentage of the file copied
partial: tells rsync to keep the partial file which should make a subsequent transfer of the rest of the file much faster.
a: Archive, It is a quick way of saying you want recursion and want to preserve almost everything.
v: Verbose
z: Compress the files so less bandwidth is needed, and the files are copied faster.

From remote to local computer

rsync –progress –partial -avz user@remote.server:/folder/to/copy/ /local/folder

If you want to copy specific files, include it in the path.

rsync –progress –partial -v /path/to/file/file.ext user@remote.server:/remote/folder/

From one folder to another folder, in the same local computer

rsync -av /source/folder /destination/folder

Synchronize two folders with rsync

If you want to keep two folders in sync rsync is also your best option.

From local to remote computer

rsync -avz –delete /source/folder user@remote.server:/destination/folder

From remote to local computer

rsync -avz –delete user@remote.server:/source/folder /destination/folder

From one folder to another on the same server

rsync -av –delete /source/folder /destination/folder

The last one is great to backup your files to an external drive, this what I usually do:

rsync -av –delete /home/guillermo/ /media/disk/backup-guillermo/

Then I can unplug the external disk, until the next rsync backup. The –delete option will delete the files in the destination folder, that have been deleted in the source folder, that way the two folders will always be in sync.

One last tip: If you need to limit bandwidth used from in a rsync backup connection use –bwlimit=KBPS and tell rsync how much bandwidth in Kbytes pers second can be used.