Majestic Online: Featured Products

Saturday, February 5, 2011

Backing up your ubuntu server with rsync

# I wanted to move data from one server to the other without a slep, i.e. new server added for the internal files

ssh rsync stuff
This was the final command
rsync -e ssh -rvpo root@192.168.0.2:/home/samba/groups/DIRTOMOVE   /home

-e execute remote command
-r recursive
-v verbose
-p preserve permissions. this is now files
-o preserve owner

I wanted to copy the data to the new server and destroy the old server

Before you can do this you have to enable the servers to log into each other.
This is achieved by ssh and exchanging keys. Once keys has been exchanged, you dont need to login in again

--------------
This is the "from" server. the server where the data currently resides.
Main sever
mkdir  ~/.ssh
if ssh is installed this directory already exists if you logged in remotely for that user.
If you have a new user, it is necassary to do that. I used root

-----------------
backupserver
ssh-keygen -t dsa
generate the key on backup server, have to enter twice

copy the key to the main server
cat ~/.ssh/id_dsa.pub | ssh ad@192.168.0.222 “cat – >> ~/.ssh/authorized_keys”
say yes etc to finish key copy

to test from the backup server ssh with the same user to the main server. it should not prompt you for a password
ssh root@192.168.0.222
Dangerous to use root, but cool if you do it once

exit out and back to backup server
------------------------

We will now perform a dry run to test our settings.
rsync -e ssh -avzn –delete-after root@192.168.0.222:/backup ~
If it is successful, i.e. no errors displayed, then proceed to the next step to run the sync manually…
rsync -e ssh -avz –delete-after  root@192.168.0.222:/backup ~
You should see some output such as this… this output could be very long depending on how many backups exist on your  server.

No comments:

Post a Comment