Write linux script for automated backup and restore
Posted on 2010-09-04
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.