Link to home
Start Free TrialLog in
Avatar of zenguru
zenguru

asked on

Write linux script for automated backup and restore


I have fedora 13 64bit on a sata 320 GB hard disk (sda). I have a second 512 GB sata hard disk sdb.

I want to partition sdb in such way that I have about 2 50 gb partitions of which one is ntfs for windows installation (mounted on fedora as /media/cdrive ) and other 50 gb for linux use from fedora. The remaining space 412 GB is used for backup as detailed below.
LVM scheme can be used on sdb. Lets call this 412 GB physical partition as sdb3.

Please write a backup script that would achieve the following tasks:

1) Runs automatically every night at 3 am on fedora if fedora machine is on.
 
2) Makes bit for bit disk image or snapshot of entire /dev/sda used space ( not the free space on /dev/sda) and save on sdb3 disk.

3) Must do some type of compression like gzip.

4) The program should backup in such a way that sdb3 contains disk images of most recent 5 days ( 5 disk images). That means on day 6, the disk image that was created on day 1 is overwritten and on day 7 , disk image that was created on day 2 is overwritten and so on. Should also account for days in which power went out or simply the system was off and skip that day automatically.

5) This program must be reliable to withstand sudden power outage in case that happens while its running.


Please write a restore script that would achieve the following tasks:

In case sda is fried up, I install a new hard disk in its place and boot the system using any linux live cd like fedora or ubuntu. From this live cd I access and run the restore script.
Restore script should achive the following:

1) I can choose which disk image ( of the 5 images in sdb3)  to use as the source for restore
2) sda now should have exactly same partions/logical volumes and data at the time the backup program above created
the disk image.
3) after this I remove the live cd and boot the system and should be able to boot to fedora.



Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Is this homework?
Avatar of zenguru
zenguru

ASKER

No its not.
so you better take a dedicated backup product like veritas Netbackup (symantech).
Avatar of zenguru

ASKER

Please provide the solution exactly as described instead pointing me to enterprise products costing $1000s. I dont need that for this purpose as you should know.

I expect some one who is expert in this subject matter ( an expert having extensive experience
in linux backup and restore -- if he did not extensive experience he would not be called
expert) in 15 minutes or less or he may already have such a script that needs some editing
to achieve the solution to the problem.

Please do not post comment unless you have extensive experience in linux based backup and restore.
Read through some of your other posts too. What an attitude !
Now good luck with your answers.
Hi!

Look at Bacula. It's a free backup program that's very powerful.

Ref: http://www.bacula.org/en/

Regards, Tobias
Avatar of zenguru

ASKER

about bacula:  its from bacula website:

 However, if you are new to Unix systems or do not have offsetting experience with a sophisticated backup package, the Bacula project does not recommend using Bacula as it is much more difficult to setup and use than tar or dump.

so it does not suit my needs. Thanks anyway. Again please do not point me to complex enterprise programs. I just need that linux script which will meet the conditions given.

Dear zenguru,

You should probably ask a bit more specific question and not ask people to do all of your work for you. And also not bash people if they recommend other solutions then the ones you had in mind. (IMHO)

But anyway...

"A simple script" - if you want to do a bit-wise comparison there are no simple things available. If you are OK with a copy of the data, then your script might look like this:

(see code)

I haven't tested this at all, it's up to you...


#!/bin/bash
DATE=$(date %Y%m%d)
TARGET=/my/backup/device
SNAP=${TARGET}/snap
mkdir -p ${TARGET}/${DATE}
mkdir -p ${SNAP}

# main backup
rsync -avz /source/* /${TARGET}/${DATE}/

# do "snapshot" if successful

if [ $? -eq 0 ]; then
tar -zcf ${SNAP}/${DATE}.tar.gz ${TARGET}/${DATE}
else;
echo "didnt work"
fi

Open in new window

you can use multiple tools to image/backup linux system  in my datacenter, i use the following:
1- use Mondo Rescue to clone linux systems:
http://www.mondorescue.org

2- You can use dd also. dd if=/dev/somedisk of=/dev/somedestination

3- rsync scripting

4- netcat
On the source server: (cd / && tar -cvf - ) | nc 192.168.1.2 2000
On the destination:: nc -l -p 2000 | tar -xvf -

5- http://sourceforge.net/projects/g4l/

6- http://www.bacula.org/en/

7- http://clonezilla.org/

8- ibm tools
http://www-01.ibm.com/software/tivoli/products/prov-mgr-os-deploy/
IBM® Tivoli® Provisioning Manager for OS Deployment helps organizations reduce the time and costs associated with desk-side support and direct interaction with target systems.

http://www-01.ibm.com/software/tivoli/products/storage-mgr/
IBM Tivoli® Storage Manager 6 provides a wide range of storage management capabilities from a single point of control, helping companies ride the information tidal wave.
ASKER CERTIFIED SOLUTION
Avatar of madunix
madunix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zenguru

ASKER

Thanks for ur post madunix.  Does rsynch creates compressed disk image of the source drive and does it include bit for bit copy including partitions and MBR ( master boot record)  while source is live and running ( not offline mode ) ?
>Does rsynch creates compressed disk image

No.

>does it include bit for bit copy including partitions and MBR

No.

rsync copies files just as they are. No compression are made to the destination file, no partition copy are available.

Regards, Tobias