sh 用tar备份和恢复linux操作系统

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 用tar备份和恢复linux操作系统相关的知识,希望对你有一定的参考价值。

#!/bin/sh

echo "Make sure update_note.txt is ready."
echo
./wait_confirm.sh

datef=`date '+%Y%m%d.%H%M'`
echo "date is: " $datef

backup_home=/mnt/whale/ubuntu16.04.2.of.1_archive/$datef
echo "backup_home: " $backup_home
mkdir -p $backup_home

./update_note.sh $backup_home $datef

# /
cd /mnt/sda2
tar -zcvf $backup_home/sda2_sys.tar.gz ./
# /boot
cd /mnt/sda3
tar -zcvf $backup_home/sda3_boot.tar.gz ./
# /boot/efi
cd /mnt/sda4
tar -zcvf $backup_home/sda4_efi.tar.gz ./
# /home
cd /mnt/sda5
tar -zcvf $backup_home/sda5_home.tar.gz ./

echo "backup is done."
#!/bin/sh

#list disk partitions
parted -l

#umount sda partitions
umount /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 /dev/sda6 /dev/sda7 /dev/sda8 /dev/sda9

# umount sdb partitions
umount /dev/sdb1

echo ""

# sw

# /
mkdir /mnt/sda2 
mount /dev/sda2 /mnt/sda2

# /boot
mkdir /mnt/sda3 
mount /dev/sda3 /mnt/sda3

# /boot/efi
mkdir /mnt/sda4 
mount /dev/sda4 /mnt/sda4

# /boot/home
mkdir /mnt/sda5
mount /dev/sda5 /mnt/sda5

# create mountpoint folder for outer disk whale 
mkdir /mnt/whale
mount /dev/sdb1 /mnt/whale

echo ""
echo "Under /mnt: "
ls -l /mnt
echo ""
df -h
#!/bin/sh

parted -l

# format swap
# mkswap will create new uuid each time it runs
# mkswap /dev/sda1
## swapon /dev/sda1

archive_file=$1
backup_home=/mnt/whale/ubuntu16.04.2.of.1_archive/$archive_file
echo "backup_home: " $backup_home

# /
mkfs.ext4 /dev/sda2
tar -zxvf $backup_home/sda2_sys.tar.gz -C /mnt/sda2

# /boot
#tar -zxvf $backup_home/sda3_boot.tar.gz -C /mnt/sda3

# /boot/efi
#tar -zxvf $backup_home/sda4_efi.tar.gz -C /mnt/sda4

# /home
mkfs.ext4 /dev/sda5
tar -zxvf $backup_home/sda5_home.tar.gz -C /mnt/sda5
#!/bin/sh

backup_home=$1
datef=$2
new_note=./update_note.txt

cp $new_note $backup_home

archive_home="$backup_home/.."
echo "archive home: " $archive_home

all_note=$archive_home/update_note.txt
echo "all_note: " $all_note

cp $all_note $all_note.old

head="\n\n$datef\n"
body=$(cat $new_note)
tail="\n"

content="$head$body$tail"

# if we omit the double quote " surrounding the viariable $content, 
#     then the output is not correct. Very strange.
printf "$content" >> $all_note
update log here:
...
#!/bin/sh

parted -l

while :
do
    echo 
    read -p "Press Ctrl + C to interrupt or press Enter to Continue: " input
    case $input in
        "" ) 
            echo "going on .." 
            break 
        ;;
    esac
done

以上是关于sh 用tar备份和恢复linux操作系统的主要内容,如果未能解决你的问题,请参考以下文章

CENTOS的备份和恢复

#yyds干货盘点#常用的 Linux 系统备份恢复命令

#yyds干货盘点#常用的 Linux 系统备份恢复命令

备份和恢复文档

用elasticsearchdump备份恢复数据

Linux文件目录及文件系统的备份与恢复相关命令