If you want to do incremental backup between two servers. Let say there is a folder /root in
your local server which you want rsync to the /tmp/ribs via SSH
You have to first define switch for rsync command -racv -e than you have to tell user
and the protocal. Here we use ssh protocal and root user so "ssh -l root" than you have
to define the IP of the remote server that is 192.168.1 and than tell where you want
to backup on remote server. We define path /tmp/ribs now you will be able to backup the
root folder of local machine to the remote server /tmp/ribs
rsync -racv -e "ssh -l root" /root 192.168.1.1:/tmp/ribs
Switch
- rsync - this syncs the local directory to with the server directory.
- -e "ssh" - this tells
rsync
to usessh
if your want to pass in other ssh options such as port you can do that in the quotes:-e "ssh -p 12345"
- -rca recursive, checksum, and archive
- --delete-after - this will delete files on the server if you delete them locally.
#!/bin/sh
rsync -racv -e "ssh -l root" /root 192.168.1.1:/tmp/ribs
Now sure make the file is executable:chmod ug+x backupscript.sh
Next type crontab -e
this will open up your scheduled tasks list, in most cases it will open an empty file. Add the following to the file:
Here we tell that to run this script everyday 9AM. This script will be run as root and the script
located in the /root folder by name /backupscript.sh will be executed
That's will schedule the script to run at AM.
Cheers!!
No comments:
Post a Comment