Hamid Fadishei's Blog

April 7, 2012

Transferring A Directory Tree Between Servers Using rsync without Passwordless SSH

Filed under: Linux — fadishei @ 7:29 am
Tags: , , , ,

Linux server administrators occasionally need to transfer files between servers. scp is a handy command line for this purpose. But there is a better approach, rsync, which will give you two advantages: First, you can resume broken transfers (even in case of multiple files and directories). Second, it skips transferring the files that are similar between source and target. Thus you may re-transfer content after modifications optimally.
rsync uses an externall remote shell, ssh in the case of this tutorial. One annoying thing is that many tutorials over the net require you to setup passwordless SSH (public key encryption) from between source and target machine which, in my opinion, is a real chore to be done as a prerequisite for a simple file transfer.
Instead, I suggest using sshpass utility which allows you to enter ssh password in command line. Don’t worry for you password being stored in bash_history! Linux has a solution for this: add a blank character at the start of the command and it will never go into ~/.bash_histry.

$ sudo apt-get install sshpass
$ [type a blank here] nohup rsync -avzl -e "sshpass -p dst_pass ssh" /path/to/src dst_user@dst_ip:/path/to/dst &

nohup is used to let you logout after issueing the command without the transfer operation being stopped. You may monitor the transfer progress at any time by using this command:

$ tail -f nohup.out

November 25, 2010

How to revert the “make install” mess?

Filed under: Linux — fadishei @ 10:20 am
Tags: ,

Aesthetically speaking, every Makefile should provide a revert target for any target that changes the file system on the host operating system. For example a make file that provides an “install” target should also provide an “uninstall” one. Unfortunately, things are not always the way they should be. Personally I always hesitate to install applications from their sources and prefer to use the package manager on my Linux as long as it provides the application I need. But what if it does not? what if the binary in the repository is not as up-to-date as you need?

I’m aware of two ways for alleviating this shortcoming. I’d be glad if you comment me about alternate solutions though.

Method 1 – Using checkinstall application

checkinstall is an application that can build binary packages (deb, rpm etc) from your sources. Then you can easily install and of course cleanly uninstall your programs. First you need to install this utility:

$ sudo apt-get install checkinstall

Then you proceed to the normal make process but at last instead of issuing “sudo make install” you will issue “sudo checkinstall”. This will build a package and also install it:

$ cd foo
$ ./configure
$ make
$ sudo checkinstall

Later if you decide to clean your system from the package “foo” you just enter:

sudo dpkg -r foo

Method 2 – Using paco application

paco (package organizer) is another useful utility to be introduced here. It works by monitoring and logging the filesystem modifications during the installation process. Then you can use the logged information to view the installed files or uninstall them

$ sudo apt-get install paco

This time, instead of doing “make install” directly, you should request paco to do the installation:

$ cd foo
$ ./configure
$ make
$ sudo paco -lp foo "make install"

Later if you decide to clean your system from the package “foo” you just enter:

sudo paco -r foo

Remember that there is a graphical interface to paco named gpaco that may be useful to be “sudo apt-get install”ed!

April 26, 2010

Linux chroot: do it perfectly!

Filed under: Linux — fadishei @ 8:26 am

Today, like many other days since I know Linux, I needed to re-install Grub on a system. The problem was that I could not boot into it. The even greater problem was that I wanted to use exactly the grub-install of the same system that I could not boot into. The solution I use in the situations like this is to boot into the system using a live-cd or anything that can drop me in a simple Linux shell (even without providing the grub-install command in that shell) and then chroot into the Linux installation I want to install grub and use its grub-install.

But simply issuing a chroot command to the mounted root is not a really perfect changing of root! You should make the special filesystems available to the target root system at first. Otherwise, you may encounter an empty /dev, and empty /proc, etc after chroot. Thus the grub-install will complain that it can not find your hard disk device nodes.

So, what you should do is to make the special filesystems available to the new root after mounting it:

# mount the target root:
mount /dev/sda2 /mnt

# mount the special filesystems:
mount -o bind /proc /mnt/proc
mount -o bind /dev /mnt/dev
mount -o bind /sys /mnt/sys

# now chroot!
chroot /mnt

# mount extra partitions if you have them separate
mount /dev/sda1 /boot
mount /dev/sda5 /var

# now you shall have no problems after issuing a grub-install
grub-install /dev/sda

Blog at WordPress.com.