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:
Code:
rsync -av --delete --exclude='/.gvfs/' --log-file=/home/andrew/Logs/rsync/$(date +%Y%m%d)_rsync.log /home/andrew/ andrew@192.168.1.70:/media/data/backups/ubuntu_home_backup/home_laptop
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.
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:
Code:
rsync -av /home/andrew/ andrew@192.168.1.70:/media/data/backups/ubuntu_home_backup/home_laptop
copies the contents of my /home to the desired location. Whereas
Code:
rsync -av /home/andrew andrew@192.168.1.70:/media/data/backups/ubuntu_home_backup/home_laptop
copies the actual /andrew folder and its contents to the desired location.
To quickly show my crontab file, I would enter
which opens my crontab file, looking something like this:
Code:
# 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:
Code:
# m h dom mon dow command
30 02 * * * /home/andrew/Scripts/backup.sh
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.
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!
Bookmarks