COPYRIGHT RESERVED 2009 BY MAX TSAI



Visit Max Tsai at Facebook | Twitter | atom

Sunday, April 27, 2008

RSYNC via SSH in CRON jobs

This is my new favor thing to do .. rsync (http://samba.anu.edu.au/rsync/) through ssh!

1. Set up SSH key pair between the same login at two hosts:
  1. At the Source Host (copy from):
    1. Do a ssh-keygen -t rsa to generate the private/public key pair
    2. It is commonly to save it under ~/.ssh as id_rsa and id_rsa.pub
    3. I would now do a sftp the public key file (id_rsa.pub) to my Target Host and save it under .ssh as authorized_keys2. At the same time, you can add the host key.
  2. Test it at the Source Host
    ssh TargetHost (no User ID required assuming the same account is used on both hosts).
  3. Working? Good!
2. Samples for RSYNC
  1. #rsync -ave ssh TargetHost:/export/test/ /export/test/
    sync'ing from Tager Host to Local Disk
  2. #rsync -ave ssh /export/test/ TargetHost:/export/test/
    sync'ing from Tager Host to Local Disk
  3. with Delete option to remove old deleted files
    #rsync -ave ssh --delete TargetHost:/export/test/ /export/test/

No comments:

Post a Comment