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

I have a code base on my production server which is synced from a remote directory. One thing I want to improve about the rsync process is to make it make a local copy first before it takes place and over write the original files. Something like

before syncing files from remote :
cp -rf production_code_base production_code_base_old
now syncing remote changes to the production directory

Is there a way to do that?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

besides the --backup-dir option (which i haven't used, so i'm not sure if it's appropriate), you could do a 'hard link backup' with cp -al production_code_base production_code_base_old. I'ts very fast since it doesn't copy the data, and it doesn't use up space for unchanged files.

Note: This is safe in this specific case because rsync never opens an existing file for writing, it writes everything to temporary files and finishes with a mv after that. Other transfer systems might overwrite existing files, destroying the hard-link 'backup'.

share|improve this answer
1  
"Never" unless you give it the --inplace flag. Rsync is very flexible. :) –  mattdm Dec 15 '10 at 3:16
    
@mattdm: you're right, of course. rsync can do almost anything, including shooting your own foot. –  Javier Dec 15 '10 at 14:23

Well, there's lots of ways to do that. Like, the cp command you just posted. Or you can use the --backup-dir option to rsync.

But what are you trying to accomplish? Might it better be done with proper version control?

share|improve this answer
    
I'm using rsync for code deployment. In case there is something going wrong with the new code. I need to backup the previous code first. The code is actually version controlled by the GIT tool. But we don't want to put the .git/ stuff to production along with the real code. –  Shawn Dec 15 '10 at 1:58
    
But, isn't the previous code also already in git? –  mattdm Dec 15 '10 at 15:47

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.