Friday, December 03, 2004

Automate Backup in Linux

Automated Backup Linux(Source) to Linux (Destination) :
=========================================

Source IP - 67.15.35.18
Destination IP - 192.168.0.17

Scenario:
=======

Here we need to backup data from 67.15.35.18 (/opt/mavb-proxy-recent/src) to 192.168.0.17 (/home/sriram)

Steps :
=====

1) First we need to automate the login process with out initializing the password.
- For that we use ssh-keygen

2) We need a Backup Script that can be run on the Backup Server (192.168.0.17) at the scheduled time.
- This script will connect using ssh, tar the specified directory and scp the directory to Backup Server and delete the tar file from the destination server.
- This can be added to cron job.

How To :
=======

1) Creating SSH-Keygen in 192.168.0.17

#ssh-keygen -t rsa

Ente the Pass Phrase
eg pass

2) Change the directory to cd /root/.ssh/ where the Public key is stored.

3)
Copy your public keys to scp id_rsa.pub 67.15.35.18:/root/.ssh/authorized_keys2

4) Check if the server asks for password

# ssh
67.15.35.18

This should log in with out asking for password.

The script I run to take the backup in 192.168.0.17 (/home/sriram)

#!/bin/sh
today=$(date +%Y%m%d-%H%M%S).tgz --- Variable Defined
ssh 67.15.35.18 "tar -cvf /opt/mavb-proxy-recent/$today /opt/mavb-proxy-recent/src " --- connects and tars(backup)
scp root@67.15.35.18:/opt/mavb-proxy-recent/$today . --- copyies the backup file to the backup server (192.168.0.17)
ssh 67.15.35.18 "rm -rf /opt/mavb-proxy-recent/$today" --- removes the backfile from the server(67.15.35.18)

No comments: