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 a novice so go easy. :) If it makes a difference I'm using Ubuntu/Debian machines.

I want to back up our dedicated web server to a local location in-house. This is for many reasons - I know that our web host will back up properly, however there are occasions when we will will release a new website and our clients will want to get access to old data and we will want to roll back to an earlier version of the site, and other similar situations.

I know that to do this I need to use rsync and cron, but I don't know much more than that. The aim is to get the latest backup onto our in-house server and then to push that backup to our network attached storage device where the previous backups are also stored.

So with rsync I will always have the latest version on the in-house server right? Rsync will only transfer files which have updated. Then from there I can run a cron which will push via rsync or SMB to the NAS box?

So my question is, assuming that my method is correct, how would I use rsync to pull down the /home directory on my remote server? Is it an easy process? Is there a beginners guide to rsync?

Can I do rsync from the local machine? We don't have a static ip address and I would like to cron this so that it does a backup automatically every night (or week depending on how long it takes and how much space it takes up).

Thanks for your help guys! :)

Tom

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Generally, your thoughts are all in the right direction. Specific answers to your questions:

  • "Can I run a cron which will push via rsync or SMB to the NAS box?"

    Yes, absolutely.

  • "How would I use rsync to pull down the /home directory on my remote server? Is it easy?

    Yes, here's the command I use. Check rsync docs for explanations:

    rsync -vrltpz --force --delete -e ssh you@yourserver.com:/home/ /backups/myserver
    
  • Is there a beginner's guide?

    Many, here's a good cookbook

  • Can I do rsync from the local machine?

    Yes. You'd run the command above from your local machine.

  • (How do you get cron to do it)?

    Also not hard. Use crontab to edit your cron table:

    $ crontab -e
    

    An editor will show up. Enter something like this to backup once a day:

    MAILTO=you@youremail.com
    @daily rsync -vrltpz --force --delete ... 
    

    Cron has ridiculously powerful control over when it runs, one Google search will get you lots of examples and crontab docs.

share|improve this answer
    
This is a brilliant answer, thank you! :) And well done for reading questions into my long post! haha. –  Thomas Clayson Apr 19 '12 at 13:36
1  
Quick question with rsync obvs I can create an ssh key and share it with the web server to get password-less entry to ssh right? Well, is this insecure? Is it bad if I use it for the root user? Or should I create a new user? If I create a new user for ssh will they have access to the /home dir (for rsync) or will I have to add them to a group which will have access? :p Sorry for all the questions! :) This kinda stuff isn't answered in all certainty on the net. –  Thomas Clayson Apr 19 '12 at 13:40
    
1) Not insecure as long as you properly protect your private key. 2) Generally, try to keep things off root as much as possible; create a new user or use whatever user already owns the files. Definitely practice in a scratch area, you'll get the feel for it. Good luck! –  ckhan Apr 20 '12 at 16:26
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.