Published 2013-03-04 00:00:00

 Backups, yes we do backup occasionally, and I've been looking for a better solutions than my historical office<->hosting replication, which although cheap, always made me wonder if I was still making copies. So after our recent office move, and minor server upgrade, I thought better double check on it all.. As usual, the thing had failed due to various reasons, and needed replacing. 

So since I've been thinking about a new solution for our clients, I decided to go ahead and try it out for our data. I've been googling affordable cloud based storage for a while and found a company, the pricing is very reasonable US$45 for 2 years currently, with unlimited everything. There are a few review sites that seem to throw some cold water over the offer, but I had one client sign up without any major issues (for another reason), so at that price I though let's give it a go....

One of the key features they advertise is rsync, which since we run all linux machines would be ideal. However after paying, and getting access, I realized it's not quite a simple as pointing your rsync at their server. You need to set up an ssh tunnel to route rsync through.

Can't be that difficult I thought.... Turns out that setting up a password based ssh tunnel, automatically on a cron job, is no small task, there are questions all over stackexchange and various forums, none that I saw managed to find a solution. Most of the suggestions are based around the 'expect' program, a usefull unix tool which can be used to script ssh access. The problem in this case was that setting up the tunnel, then doing the rsync, and then closing the tunnel is not something that a bash, expect or any other method I found could do easily if at all.

So almost at the point of giving up, I started looking around at php's popen (which would not work either), and fell over the pecl expect extension. 

Below is the result of a few minutes coding, which does exactly what is needed, and can be run directly from cron. Feel free to escape from overpriced backup solutions..

$username = 'xxxx';
$password = 'xxxx';
$backup_what = '/home';
$target = 'myhome'

ini_set("expect.loguser", "Off");

// forward remote port on the ols server:873 to localhost:9873

$stream = fopen("expect://ssh {$username} -L9873:localhost:873", "r");

$cases = array (
    array ("password:",  'password'),
    array( "yes/no)?", 'yes'),
    array( "Terminal", 'terminal'),
while (true) {
    $x = expect_expectl ($stream, $cases);
    switch ($x) {
        case 'terminal': 

        case 'password':
            fwrite ($stream, $password."\n");

        case 'yes':
            fwrite ($stream, "yes\n");
            echo $x; // usuall -1 as line was not matched..
            die ("Error was occurred while connecting to the remote host!\n");

    if ($x == 'terminal') {
    //echo "break while";    


passthru("/usr/bin/rsync -a {$backup_what} rsync://{$username}@localhost:9873/{$username}/{$target}');

fclose ($stream);


Wrong service provider URL
I think you meant to link to (without the 's')
#0 - Pies ( Link) on 2013-03-06 21:35:27 Delete Comment
Interesting extension. I'll have to test it.
#1 - hyh ( Link) on 2013-03-13 16:36:54 Delete Comment
The hilarious moments are very few because life is the name of seriousness. The comical or funny people try their best to make the moments so bright. This work is not easy because you have to utilize your all senses.
#2 - susanrichard ( Link) on 2017-11-10 15:16:58 Delete Comment
Top Universities that Welcome International Students for Creative Writing
In the present day, the number of international students is increasing every year. Students love to study in a foreign country and many students dream of studying abroad when they are very young. It is possible for students who are dreaming of studying abroad since more and more universities, colleges and schools across the world welcomes international students. If you look at the classrooms of universities, colleges and schools across the world you will be able to find out a number of students who are from out of country. Diversity is not only seen in public life but also in the classroom and it is always a great thing to have diversity in classroom as it enhances learning.
#3 - buy essays ( Link) on 2018-03-27 14:29:01 Delete Comment
health information
Gracia Clinic is one of the largest clinics in Jakarta today. With complete and modern medical equipment, Gracia Clinic is ready to compete with other clones and hospitals inside and outside Jakarta.
#4 - gracia ( Link) on 2018-04-11 15:52:02 Delete Comment
Green Tea
Wow, happy to see this awesome post. I hope this think help any newbie for their awesome work. By the way thanks for share this awesomeness from
#5 - Green Tea ( Link) on 2018-05-06 05:27:24 Delete Comment
Valerian Essential Oil
I read that Post and got it fine and informative. Please share more like that...
#6 - Valerian Essential Oil ( Link) on 2018-05-07 21:03:03 Delete Comment
cayenne pepper
Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
#7 - Cayenne Pepper ( Link) on 2018-05-07 21:05:58 Delete Comment
Tangerine Essential Oil
Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.
#8 - Tangerine Essential Oil ( Link) on 2018-05-07 21:08:22 Delete Comment
Punicic Acid
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work
#9 - Punicic Acid ( Link) on 2018-05-07 21:11:37 Delete Comment
Vanilla Essential Oil
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work
#10 - Vanilla Essential Oil ( Link) on 2018-05-07 21:16:54 Delete Comment
This will be good information for all those who are looking for the PHP code. It will be good if you add some more contents here. Hope you will share it as soon as possible.

Add Your Comment

Follow us on