I have actually recently been tinkering with rsync and cron to back up to a remote computer on the local network and have gotten it to successfully run at 2:30 AM every night. Just some other stuff to throw out there for others:
I am using the
option, which is nice depending on what your trying to accomplish. It will automatically delete anything in the "backup directory" that has been deleted in the directory that your backing up. Some users may like this, others may not.
Also, an FYI to others, for some reason I had to use the
option when backing up /home. Otherwise rsync seemed to be caught in an endless loop.
I also like having the output saved into a log file in designated directory so that if I want at a later time, I can review what was actually copied or removed.
My actual command which I have saved to a .sh script is:
You'll notice the --log-file argument. It will output it to a file named today'sdate_rsync.log where the today'sdate is in the format 20100311 for easy cataloging.
rsync -av --delete --exclude='/.gvfs/' --log-file=/home/andrew/Logs/rsync/$(date +%Y%m%d)_rsync.log /home/andrew/ email@example.com:/media/data/backups/ubuntu_home_backup/home_laptop
I also don't have to specify it to use ssh -e because, if I am not mistaken, by telling rsync to copy to a remote location, it defaults to ssh with port 22. I may be wrong but this is what works for me.
Also be aware that rsync pays particular attention to the / at the end of a path. If it is there, it will copy only the contents of that directory into the desired location. If it is not there, it will copy the the actual directory and its contents. For example:
copies the contents of my /home to the desired location. Whereas
rsync -av /home/andrew/ firstname.lastname@example.org:/media/data/backups/ubuntu_home_backup/home_laptop
copies the actual /andrew folder and its contents to the desired location.
rsync -av /home/andrew email@example.com:/media/data/backups/ubuntu_home_backup/home_laptop
To quickly show my crontab file, I would enter
which opens my crontab file, looking something like this:
# m h dom mon dow command
Explaing the use of CRON is beyond the scope of this thread but for those who are curious about mine, it is:
which allows me to run the backup script above at 2:30 AM everyday when I am soundly sleeping and the computer isn't doing anything else.
# m h dom mon dow command
30 02 * * * /home/andrew/Scripts/backup.sh
Great tutorial and I hope my two cents will help someone else down the road in return for all the help that I have gotten over the years!