rsync full backup script of working server

Joined
May 12, 2010
Messages
1,663
Points
0
Lately I needed to clone an Elastix LVM machine and I've been doing some tests with rsync.
I would like to share here my scripts to clone a working Elastix server.

Maybe you can include it somehow in the web backup interface.


The starting point is a running Elastix server.
I wanted to completely clone it to another machine (it seems to work for different hardware too).

In the running source server, you just need to install rsync using "yum -y install rsync"
Let's say server has ip 192.168.1.100


So all commands here are run at the destination machine.

The destination machine is a clean elastix install using the same version.
I have used latest 1.3 stable.
After using "setup" to change keyboard preferences and network configuration



So first you have to configure passwordless ssh access.

First generate your local ssh keys.
I do all this as root.
Code:
ssh-keygen -t dsa
(enter no password here and leave the default output folder)


Then create a file called sshscript.sh with the following contents:
Code:
KEY="$HOME/.ssh/id_dsa.pub"

if [ ! -f ~/.ssh/id_dsa.pub ];then
    echo "Clave privada no encontrada en $KEY"
    echo "Por favor, creala con "ssh-keygen -t dsa""
    echo "* Para conectar con un equipo remoto sin contraseña, no le pongas contraseña a la clave creada con ssh-keygen! *"
    exit
fi

if [ -z $1 ];then
    echo "Por favor, especifica usuarioATexample.com como parámetro para este script"
    exit
fi

echo "Poniendo tu clave en $1... "

KEYCODE=`cat $KEY`
ssh -q $1 "mkdir ~/.ssh 2>/dev/null; chmod 700 ~/.ssh; echo "$KEYCODE" >> ~/.ssh/authorized_keys; chmod 644 ~/.ssh/authorized_keys"

echo "ok!"

Now you run the script putting as arguments the source server's ip address.


Code:
chmod +x sshscript.sh
./sshscript.sh rootAT192.168.1.100
This should ask you for the root password and say ok.

Now you can try to access without password:
Code:
ssh rootAT192.168.1.100
Ok. Now we have full access to the server for the script to copy files as root at will.
Remember to exit the ssh session to the server!

Now create a file called rsyncbackup.sh with the following contents:
Code:
yum -y install rsync
rm -rf /home/reporte.txt
sudo nohup rsync -avz --delete --exclude='/sys' --exclude='/proc' --exclude='/boot' --exclude='/etc/fstab' --exclude='/etc/lvm' --exclude='/var/cache' --exclude='/etc/sysconfig' --exclude='/dev' rootAT192.168.1.100:/ / > /home/files.txt &
tail /home/files.txt >> /home/reporte.txt
echo "La copia ha finalizado en la fecha" >> /home/reporte.txt
date >> /home/reporte.txt
chmod 777 /home/*.txt
tail -f /home/files.txt
Now you can run the script:
Code:
chmod +x rsyncbackup.sh
./rsyncbackup.sh
You can see the last command is "tail -f /home/files.txt"
So, you can exit at anytime with contol-c, but this won't stop the script from running, you just stop watching file /home/files.txt
If you want to stop it you'll have to manually kill rsync process.

Of course you'll have to reconfigure zaptel and tweak some hardware modules in the destination machine if you have different hardware.

This even works if the source machine is using LVM and the destination machine isn't.

I hope this helps you!


IMPORTANT NOTE: You will have to substitute in all the scripts "AT" for "@"
This is because this damn fireboard forum messes up with what it detects as email addresses inside the code tags.


Look at what happens when I insert an email address into the code tags:
Code:
elastix@example.com
Outside the code it works fine:
elastix@example.com
 
Joined
Nov 23, 2009
Messages
2
Points
0
DO NOT RUN THIS FILE FROM THE SOURCE SERVER BUT FROM THE DESTINATION SERVER.
IF YOU WILL RUN THIS FILE FROM THE SOURCE SERVER YOU WILL LOSE ALL UP TO DATE CONFIGURATIONS.
 

Members online

No members online now.

Latest posts

Forum statistics

Threads
30,987
Messages
131,100
Members
17,716
Latest member
Orbit114
Top