tags:

views:

105

answers:

1

OK, I'm probably not the first person to attempt to put together a PHP web-based interface to rsync to ease deployment, but there goes.

We have a 'QA' server locally and a 'Staging' server at Rackspace. I've set up SSH key pairings so I can rsync between the two servers and it all works great. The problem is that rsync is a bit flaky as to what it decides needs updating.

The script I have written first executes rsync with the '--dry-run' parameter to get a list of everything that needs transferring. The command is as follows:

$strCheck = shell_exec(
                       "rsync " .
                       "--verbose " .
                       "--recursive " .
                       "--safe-links " .
                       "--checksum " .
                       "--dry-run " .
                       "--delete " .
                       "--delete-excluded " .
                       "--force " .
                       "--cvs-exclude " .
                       "--human-readable " .
                       "/apps/{$system}/ " .
                       "user@liveserver:/apps/{$system}_staging/"
                       );

Now this all works fine and I can parse the string that's returned into stuff that needs deleting and stuff that needs adding/updating. I then construct a HTML table that automatically indents each checkbox based on where it is in the hierarchy. I also use a bit of javascript so I can allow the user to select all files in a folder.

If a folder itself is to be added/deleted, it includes it in the list. For example:

/newfolder/
/newfolder/file1.php
/newfolder/file2.php

which is great, because '/newfolder/' will be displayed with one indent and '/newfolder/file1.php' and '/newfolder/file2.php' will each be displayed with two indents underneath '/newfolder/'. The checkbox next to '/newfolder/' will automatically select the two 'child' files and everyone is happy.

However, if it is just adding/updating files to a folder, it omits the folder itself:

/oldfolder/filea.php
/oldfolder/fileb.php

...

Which means all the files in '/oldfolder/' will have two indents, but there is no visible mechanism with which to select all the files in the folder.

So my question is this: is there something I am missing in the available rsync parameters where I can force it to include the folder for any updated files, or am I going to have to add them in as I loop through the array? If it's the latter, what would be the best way of doing that?

Help me Obi Stack Overflowbi, you're my only hope...

+2  A: 

Since the directory does not need to be created or deleted it will be missing from the list rsync returns. I don't believe there is any way to fix that.

I think your best bet would be to get the paths something like this

$path = explode(PATH_SEPARATOR, dirname($filename) );

Where $filename is your files name.

PHP-Steven
Cheers for your answer. It looks like there is no way to do this in rsync.
meanstreakuk