Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server with 2 directories: 1 is a development site, the other is the live site.

I'd like to work on the development site, and with a simple command simply move across and overrite any files on the live site that have been updated.

I understand there is git, and I have some understanding with that, but I wonder if there is a more direct route.

Any suggestions? Is there a linux command to compare 2 directories and copy across new files from one to the other while maintaining directories recursively etc?

Thanks.

share|improve this question
2  
Figuring out git is a worthwhile investment in time. One caution with the rsync command described by MadHatter is that you may want to go back to the previous version quickly. At least with git (or at least version-controlled deployment), you have rollback functionality if you've done things correctly, so you can return production to a known good condition with a few (one?) command. Related: with rsync, you may blow away something you care about, and not have a version to fall back on. –  cjc Jul 19 '12 at 12:28
add comment

2 Answers

up vote 6 down vote accepted

Basically, rsync is your tool, provided you can find a channel to run it over.

Assuming that I can ssh from devbox to prodbox, I might sync the site directories as you suggest with

devbox% rsync -avl -e ssh /opt/site/ prodbox:/opt/site/

rsync has many other flags that you might want to use, to do with deletion of files on the destination that don't exist on the source, conditions for copying, and so on; check the man page for details.

Edit: in the light of your comment (and in fairness, I think you did explain it, I just failed to pick up on it) that makes life even easier. Try

box% rsync -avl /home/sites/devfolder/ /home/sites/livefolder/
share|improve this answer
    
Sorry, I don't think I explained my situation properly - the development folder and live server are on the same box side by side e.g. /home/sites/devfolder and /home/sites/livefolder –  willdanceforfun Jul 19 '12 at 9:35
    
thanks for that! What is the box% and devbox% for? Do I type those or just start from 'rsync'? –  willdanceforfun Jul 19 '12 at 9:52
1  
they are "prompts" at the beginning of the shell line. It is for illustrative purposes "development box", "production box" etc. you do not type them. –  hayalci Jul 19 '12 at 11:23
    
@hayalci thanks for explaining that. –  willdanceforfun Jul 19 '12 at 12:23
add comment

I'd like to add that if you want to "overrite any files on the live site that have been updated", you should use the '-u' command-line switch of rsync.

share|improve this answer
    
Cheers. Thats helpful. –  willdanceforfun Jul 19 '12 at 17:04
    
nope, -u actually keeps the files updated on the target side. see man page. ""... skip any files which exist on the destination and have a modified time that is newer than the source file"" –  hayalci Dec 3 '12 at 17:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.