online marketing

Automatic Backup With Rsync And Cron On Ubuntu


Keeping a directory automatically backed up somewhere is always useful. Every few months this is needed on one machine or another. Here are the steps:

  1. First set up ssh keys so passwords are no longer needed.
    1. Test things by verifying a ’ssh user@yourserver.com’ does require a password.
    2. Make some ssh keys on your client and then move the public key to the server
      1. cd ~/.ssh
      2. ls
      3. ssh-keygen -t dsa (Keep the defaults by just pressing enter a few times.)
      4. scp id_dsa.pub user@yoursever.com:.ssh/
    3. Now set things right on the server
      1. ssh user@yourserver.com
      2. cd ~/.ssh
      3. cat id_dsa.pub >> authorized_keys
      4. rm id_dsa.pub
      5. exit
    4. Test things by verifying a ’ssh user@yourserver.com’ no longer requires a password.
  2. Determine the directory to be backed up and where it will be backed up and test the command to be used.
    1. time rsync -atvz ~/local-directory-of-your-choosing/ user@youserver.com:remote-directory-of-your-choosing/
    2. log in the server and verify the files are there…
  3. Put the command in cron. Because cron is broken in ubuntu you can’t simply do “crontab -e” anylonger. (How can something so basic be broken?!) Instead follow these instructions:
    1. vi ~/some_file and put in the cron commands
    2. @hourly rsync -atvz ~/local-directory-of-your-choosing/ user@youserver.com:remote-directory-of-your-choosing/
    3. crontab ~/some_file
    4. crontab -l

Now simply test it out…

Sumber :

http://ioconnor.wordpress.com/2009/07/25/automatic-backup-with-rsync-and-cron-on-ubuntu/

  • Share/Bookmark
  1. No comments yet.
(will not be published)