Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm following along with a Railscast that teaches how to set up Chef solo. It uses two interesting terminal commands that I had never seen before, only one of which I can get to work. When I do

scp -r root@198.xxx.xxx.xxx:/var/chef .

It copies the contents of the remote server directory to my local machine. The following command is supposed to sync the files back to the server after I change them on my machine

rsync -r . root@198.XXX.XXX.XXX:/var/chef

However, the changes aren't showing on the remote server, and when I run the chef commands that are supposed to apply the changes, it's not showing any changes that need to be made.

Am I using rsync incorrectly?

Update

Running this command gave the following output. Still no changes are shown on the remote server

rsync -rvv . root@198.XXX.XXX.XXX:/var/chef


`building file list ... 
done
delta-transmission enabled
chef/node.json
chef/solo.rb
chef/cache/chef-client-running.pid
chef/cache/chef-stacktrace.out
chef/chef/node.json
chef/chef/solo.rb
chef/chef/cache/chef-client-running.pid
chef/chef/cache/chef-stacktrace.out
chef/chef/cookbooks/main/recipes/default.rb
chef/cookbooks/main/recipes/default.rb
chef/cookbooks/main/templates/default/zshrc.erb
total: matches=17  hash_hits=17  false_alarms=0 data=0
sent 1167 bytes  received 442 bytes  643.60 bytes/sec
total size is 6236  speedup is 3.88`

Update

You'll notice from the above update that a templates directory should be inside the main directory (along with a recipes directory), however, this is what's showing

root@Chef3:/var/chef/cookbooks# cd main
root@Chef3:/var/chef/cookbooks/main# ls
recipes
share|improve this question
    
What's the output of rsync -rv . root@198.XXX.XXX.XXX:/var/chef? You are indeed using rsync incorrectly (not your fault, looks like a bad tutorial), but not in a way that should cause the changed files not to be transferred. –  Gilles Jul 21 '13 at 0:22
    
Thanks, It says, "building file list ... done" and then it lists the files. However, they still haven't been copied to the remote server (at least the changes aren't apparent on the remote server) –  Leahcim Jul 21 '13 at 0:25
1  
Is that the list of all the files in the directory? If not, which ones are missing? Are you sure the edited files aren't being transmitted? –  Gilles Jul 21 '13 at 0:58
1  
I have my money on 1 of 2 things: no diskspace to write files or the files are there. –  slm Jul 21 '13 at 1:00
2  
@Leahcim Are there symbolic links involved? Please post the output of ls -ld * chef/node.json. Is it normal that you have a chef directory inside the chef` directory | could that be causing the confusion? –  Gilles Jul 21 '13 at 1:58

1 Answer 1

up vote 1 down vote accepted

You have two file hierarchies mixed up: /var/chef and /var/chef/chef. It looks like you're editing one and then reading back the other.

scp -r root@198.xxx.xxx.xxx:/var/chef . creates a chef directory inside the current directory. If you ran that from /var/chef.


The proposed commands are terrible. Forget everything you read in that tutorial.

scp -r does not preserve file permissions or times. Use scp -rp to preserve them.

rsync -r does not preserve file permissions or times. Forget that the -r option exists. Use rsync -a instead, which preserves all usual metadata. Always pass the -a option to rsync unless you have a good reason not to.

When you write rsync -a /path/to/source /path/to/destination, this creates a subdirectory called source under destination. If you want to synchronize /path/to/source with /path/to/destination instead, add a final / at the end of the destination: rsync -a /path/to/source /path/to/destination/ copies /path/to/source/somefile to /path/to/destination/somefile.

It's very important to preserve the file's modification times. That way you know when a file has last been modified. Your tools also know when a file has been modified. In particular, synchronizing a large directory in which most files haven't been modified is a lot faster if the file times are reliable. Rsync will skip a file quickly if the name, size and modification time are the same on both sides.

You can tell rsync to transfer only files that are newer on the source side by adding the -u option (rsync -au SOURCE DESTINATION). This limits the risks if the files have also been edited on the destination side: you won't erase the newer version that is on the destination side with the older copy on the source side. However you cannot reliably detect conflicts: if a file has been edited on both sides, whichever version has the most recent modification time will win.

Rsync is a tool to synchronize data in one direction. Do not use it to synchronize in both directions. Instead, use Unison. Unison maintains a list of file versions each time you run it and will complain loudly if there is ever a conflict (same file edited independently on both sides). As long as there is no conflict (i.e. as long as each file is only modified on one side between synchronizations), Unison will merge the changes on the two sides.

To set up Unison, use the GUI, or create a preferences file called ~/.unison/chef.prf containing

root = /var/chef
root = server.example.com:/var/chef
times = true

Run unison -auto chef to synchronize the two trees.

Rather than synchronizing files, you should put your files under version control. When you've made changes, commit them to the repository. To deploy your changes, check them out on the server.

share|improve this answer

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.