A self-written script for Automatic Recovery of system backup on the New Hard Disk

Source: Internet
Author: User
Tags unpack

Note:
We have developed a quasi-embedded system based on FreeBSD. The basic system is stored on the Dom, and the user data is stored on the hard disk. Because the system is complex, it is cumbersome to restore/install the system each time. Write a script on your own. Automatic Installation is implemented.
This includes automatic partitioning and formatting of hard disks. If you are interested, you can check it out :)
Thank you for your advice! :)

#! /Bin/sh

# Root directory
Base_dir =/root/autobuild/backup-pack
Backup_dir = "$ base_dir"/netengine/system-Backup

# Partition directory
Usr_dir =/mnt/usr
Var_dir =/mnt/var
Tmp_dir =/mnt/tmp
Home_dir =/mnt/home

# Device
Disklabel =/sbin/disklabel
Devicedir = Dev
Harddisk = AD1
DOM = ad2
Label = S1
Partitionfile =/tmp/partition
Usrnum = d
Varnum = E
Tmpnum = f
Homenum = G
Dom_device =/"$ devicedir"/"$ dom"

# Auto fdisk
# Get harddisk memory
Disksize = '$ disklabel/"$ devicedir"/"$ harddisk" | grep "sectors/unit" | awk' {print $2 }''

Disksize = 'expr $ disksize-409600'
 
# Get USR spec
Usrsize = 'expr $ disksize/10/* 5'

# Get var memory
Varsize = 'expr $ disksize/10/* 2'

# Get TMP memory
Tmpsize = 'expr $ disksize/10/* 1-20000'
Tmpoffset = 'expr $ usrsize + $ varsize'

# Get Home memory
Homesize = 'expr $ disksize/10/* 2'
Homeoffset = 'expr $ tmpoffset + $ tmpsize'

# Get swap offset
Swapoffset = 'expr $ homeoffset + $ homesize'

# Confirm TMP memory

# Initial harddisk
Echo-n "init harddisk partition ..."
DD>/dev/null 2> & 1 If =/dev/Zero of =/"$ devicedir"/"$ harddisk" BS = 1 k count = 1
Fdisk>/dev/null 2> & 1-Bi/"$ devicedir"/"$ harddisk"
$ Disklabel>/dev/null 2> & 1-B-w-r $ harddisk $ label auto
$ Disklabel> $ partitionfile/"$ devicedir"/"$ harddisk" $ label

# Initial partition table
Echo "D: $ usrsize 0 4.2bsd 2048 16384 89" >>$ partitionfile
Echo "E: $ varsize $ usrsize 4.2bsd 2048 16384 89" >>$ partitionfile
Echo "F: $ tmpsize $ tmpoffset 4.2bsd 2048 16384 89" >>$ partitionfile
Echo "G: $ homesize $ homeoffset 4.2bsd 2048 16384 89" >>$ partitionfile
Echo "H: 409600 $ swapoffset swap" >>$ partitionfile

# Auto Partition
$ Disklabel>/dev/null 2> & 1-r/"$ devicedir"/"$ harddisk" $ label $ partitionfile
Echo "done"

# Create File System
Echo-n "format harddisk ..."
Newfs>/dev/null 2> & 1/"$ devicedir"/"$ harddisk" $ label $ usrnum
Newfs>/dev/null 2> & 1/"$ devicedir"/"$ harddisk" $ label $ Varnum
Newfs>/dev/null 2> & 1/"$ devicedir"/"$ harddisk" $ label $ homenum
Newfs>/dev/null 2> & 1/"$ devicedir"/"$ harddisk" $ label $ tmpnum
Echo "done"

# Mount all harddisk Partition
Echo-n "Mount all partition ..."
Mount/"$ devicedir"/"$ harddisk" $ label $ usrnum $ usr_dir
Mount/"$ devicedir"/"$ harddisk" $ label $ Varnum $ var_dir
Mount/"$ devicedir"/"$ harddisk" $ label $ homenum $ home_dir
Mount/"$ devicedir"/"$ harddisk" $ label $ tmpnum $ tmp_dir
Echo "done"

# Auto burn Dom Image
Echo-n "burn Dom image ..."
DD>/dev/null 2> & 1 If = $ backup_dir/NetEngine-dombak.img of = $ dom_device
Echo "done"

# Auto uncompress tar.gz pack to harddisk
CD $ usr_dir
Echo-n "unpack USR directory ..."
Tar>/dev/null 2> & 1 zxvf $ backup_dir/usrbak.tar.gz ./
Echo "done"

CD $ var_dir
Echo-n "unpack var directory ..."
Tar>/dev/null 2> & 1 zxvf $ backup_dir/varbak.tar.gz ./
Echo "done"

CD $ tmp_dir
Echo-n "unpack tmp directory ..."
Tar>/dev/null 2> & 1 zxvf $ backup_dir/tmpbak.tar.gz ./
Echo "done"

CD $ home_dir
Echo-n "unpack home directory ..."
Tar>/dev/null 2> & 1 zxvf $ backup_dir/homebak.tar.gz ./
Echo "done"

# Umount harddisk
CD/
Echo-n "unmount all partition ..."
Umount $ usr_dir $ var_dir $ tmp_dir $ home_dir
Echo "done"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.