3. Shell 脚本

Shell 脚本 (shivalik Ver. 1.0) 是一种备份重要文件和信息的便捷方法。下载脚本后

现在您可以执行(运行)上述脚本(请记住您必须是 “root” 用户才能执行此操作)——输入 ./shivalik

该脚本有详细的文档记录。它不会修改(或删除)您的任何文件或目录。它为一些重要的文件和信息创建了受良好保护的备份。整个脚本可供您浏览并了解其工作原理。您可以随意查看脚本并添加任何其他功能或您希望备份的文件。您也可以将您的反馈发送给该脚本的作者 ().

请记住,shivalik 脚本不是用于完整备份和恢复的工具。理想情况下,最好的做法是完整复制您的整个 Linux 安装以及所有文件和目录。但这并非总是可能、必要或可取的。次好的做法是备份最重要的信息和文件。shivalik 脚本为您实现了这一点。该脚本创建一个名为/root/postinfo/,并将所有重要信息(和文件)存储在那里。为了完全为任何意外情况做好准备,您必须复制整个/root/postinfo/到可移动介质上,一旦脚本执行。

恢复和修复: 如果以后出现任何问题,您可以通过复制您在/root/postinfo/目录中的文件来重建损坏的文件。就这么简单。

的结构/root/postinfo/目录以及其中找到的文件,将如下所示

/root/postinfo/summary

包含系统状态的摘要报告(内存、分区、挂载点、磁盘使用情况)。此文件还包含已保存文件的列表。它还包含管理员信息,如备份日期和时间、shivalik 版本号等。

/root/postinfo/postinfo.tar.gz

包含先前 postinfo 的副本(如果有)。这是一个备用方案的备用方案!

/root/postinfo/snapshot.gz

包含 Linux 系统所有文件和目录的 gzipped 结构化列表(目录“树”)。您可以解压此文件并使用任何纯文本编辑器来了解任何文件的位置。当然,除非您已在其他地方显式保存了该文件的内容,否则您无法检索该文件的内容。

/root/postinfo/shivalik

这是用于进行安装后备份的 shivalik 脚本的副本。在事件发生后的恢复时,您可以随时检查此脚本以了解之前是如何进行备份的。您将始终拥有脚本及其创建的文件的一致副本。

/root/postinfo/etcfiles/

子目录包含来自/etc/Linux 安装目录。它还包含存储在/etc/目录中。

/root/postinfo/otherfiles/

子目录包含一些重要文件的副本(那些不在/etc/目录)的 Linux 安装目录)。如果您愿意,您可以在此处添加任何其他文件,并使其与其他文件一起自动保存。

3.1. 脚本...

#-----------------------------------------------
#           shivalik  \(Ver. 1.0\)
#Please read the WARNING section of this script first

#This script collects post installation information
#this can also be run occasionally to collect all useful
#information about your Linux installation, in one place
#The output will be written to /root/postinfo/
#a summary report will be written in /root/postinfo/summary

#For usage and related information, please consult:
#http://algolog.tripod.com/postlnx.htm
# ----------------------------------------------

clear
echo
echo "-----------------------------------------------------------"
echo This is the output of Partha\'s shivalik script \(Ver.1.0\)
echo You must be \"root\", for this script to work correctly
echo You must also read and accept the terms and warnings given
echo in the WARNINGS section of this script
echo "-----------------------------------------------------------"
echo
echo "### STEP 0 ### Preparation work"
echo First we create the /root/postinfo/ directory if does not exist already
test ! -d /root/postinfo && mkdir /root/postinfo

echo Saving current version of all postinfo files
echo But first we delete the earlier version i.e. current-1 version
test -e /root/postinfo/oldpostinfo* &&  rm /root/postinfo/oldpostinfo.tar.gz
#the oldpostinfo file is made temporarily in /root
#it will be moved to /root/postinfo
tar -zcvf /root/oldpostinfo.tar.gz /root/postinfo/*

#check if above tar succeeded
if
test -s /root/oldpostinfo.tar.gz
then 
echo old postinfo saved in /root/oldpostinfo.tar.gz
ls -l /root/oldpostinfo*
else
echo Could not save oldpostinfo
echo Abandoning shivalik script
exit
fi


#now delete all the current postinfofiles
rm -rf /root/postinfo/*
#and start a new summary file
echo  shivalik \(Ver. 1.0\) > /root/postinfo/summary
echo -n "Report created on: " >> /root/postinfo/summary
date -R >> /root/postinfo/summary
echo And now, move the oldpostinfo file to /root/postinfo/ directory
mv /root/oldpostinfo.tar.gz /root/postinfo
#

#copy the shivalik script
echo charity begins at home
echo We make a copy of the shivalik script
echo We make a copy of the shivalik script >> /root/postinfo/summary
echo in /root/postinfo/ >> /root/postinfo/summary
cp ./shivalik /root/postinfo/shivalik

#taking stock
echo
echo Contents of /root/postinfo at the end of STEP-0
ls -AlR /root/postinfo
echo End of "### STEP 0 ###
echo
#
#
echo
echo "### STEP 1 ### Make a snapshot of the system"
echo >> /root/postinfo/summary
echo "### STEP 1 ### A snapshot of all the files and directories" >>  /root/postinfo/summary
echo The first step is to take stock of your computer contents
echo This is going to take several minutes
echo So, go and fetch your coffee mug !
ls -AlRH / >> /root/postinfo/snapshot
rm -f /root/postinfo/snapshot.gz
gzip /root/postinfo/snapshot
echo snapshot created
echo An exhaustive listing of all files has been made and >> /root/postinfo/summary
echo stored in /root/postinfo/snapshot.gz >> /root/postinfo/summary
ls -l /root/postinfo/snapshot.gz >> /root/postinfo/summary

# taking stock at the end of this step
echo
echo Contents of /root/postinfo at the end of this STEP
ls -l /root/postinfo
echo End of "### STEP 1 ###
echo
#
#
echo

echo "### STEP 2 ### Vital statistics"
echo >> /root/postinfo/summary
echo "### STEP 2 ### Vital statistics" >> /root/postinfo/summary

echo Collecting vital statistics

echo .....about memory
echo "---- cat /proc/meminfo ---------" >> /root/postinfo/summary
cat /proc/meminfo >> /root/postinfo/summary

echo .....about partitions and mountpoints
echo "---- cat /proc/partitions---------" >> /root/postinfo/summary
cat /proc/partitions >> /root/postinfo/summary

echo .....about diskspace used
echo "---- df ---------" >> /root/postinfo/summary
df >> /root/postinfo/summary

echo .....about modules
echo "---- cat /proc/modules ---------" >> /root/postinfo/summary
cat /proc/modules >> /root/postinfo/summary

# taking stock at the end of this step

echo
echo Contents of /root/postinfo at the end of STEP-2
ls -AlR /root/postinfo
echo End of "### STEP 2 ###
echo
#
#
echo
echo "### STEP 3 ### Now we save some important files from /etc "
echo This section may need some customising, depending on the
echo installation you have done, and the distribution you have used, 
echo and the options you have chosen during installation.

echo >> /root/postinfo/summary
echo "### STEP 3 ### Now we save some important files from /etc" >>  /root/postinfo/summary
test ! -d /root/postinfo/etcfiles && mkdir /root/postinfo/etcfiles

echo ..... saving XF86Config -- your XWindows config file
cp /etc/XF86Config /root/postinfo/etcfiles
echo "cp /etc/XF86Config /root/postinfo/" >> /root/postinfo/summary

echo ..... saving /etc/fstab file
cp /etc/fstab  /root/postinfo/etcfiles
echo "cp /etc/fstab /root/postinfo/" >> /root/postinfo/summary

echo ..... saving /etc/profile file
cp /etc/profile  /root/postinfo/etcfiles
echo "cp /etc/profile /root/postinfo/" >> /root/postinfo/summary

echo ..... saving /etc/profile.local file
cp /etc/profile.local  /root/postinfo/etcfiles
echo "cp /etc/profile.local /root/postinfo/" >> /root/postinfo/summary

echo ".... saving /etc/*conf files"
cp /etc/*conf /root/postinfo/etcfiles

echo ".... saving /etc/*config files"
cp /etc/*config /root/postinfo/etcfiles

echo the following files from /etc have been copied to  /root/postinfo/etcfiles >> /root/postinfo/summary
echo "/etc/*conf" >> /root/postinfo/summary
echo "/etc/*config" >> /root/postinfo/summary

# taking stock at the end of this step
echo
echo Contents of /root/postinfo at the end of this STEP-3
ls -AlR /root/postinfo
echo End of "### STEP 3 ###
echo
#
#

echo
echo "### STEP 4 ### Now we save some other important files"
echo This section may need some customising, depending on the
echo installation you have done, and the distribution you have used,
echo and the options you have chosen for the installation
echo The following stuff is  designed for SuSe  7.1

echo "### STEP 4 ### Now we save some other important files" >>  /root/postinfo/summary
echo in /root/postinfo/otherfiles >> /root/postinfo/summary
echo You can add any other files to backed up, here
test ! -d /root/postinfo/otherfiles && mkdir /root/postinfo/otherfiles
ls -l /root/postinfo/

echo ..... saving /etc/init.d/boot.local --
cp /etc/init.d/boot.local /root/postinfo/otherfiles
echo "cp /etc/init.d/boot.local /root/postinfo/otherfiles" >>  /root/postinfo/summary

echo ..... saving /etc/init.d/halt.local --
cp /etc/init.d/halt.local /root/postinfo/otherfiles
echo "cp /etc/init.d/halt.local /root/postinfo/otherfiles" >>  /root/postinfo/summary

# taking stock at the end of this step
echo
echo Contents of /root/postinfo at the end of this STEP-4
ls -AlR /root/postinfo
echo End of "### STEP 4 ###
echo

echo
echo "### STEP 999 ### Wrap up, clean up"
echo >> /root/postinfo/summary

echo "### STEP 999 ### Wrap up, clean up, sum up" >>  /root/postinfo/summary
echo summing up, cleaning up
# for security reasons we make /root/postinfo inaccessible to
# and invisible to non-root
chmod 700 /root/postinfo
chmod 700 /root/postinfo/etcfiles
chmod 700 /root/postinfo/otherfiles
chmod 700 /root/postinfo/*
chmod 700 /root/postinfo/etcfiles/*
chmod 700 /root/postinfo/otherfiles/*
echo This is the contents of /root/postinfo >> /root/postinfo/summary
ls -AlR /root/postinfo >> /root/postinfo/summary
echo "###### THE END #####" >> /root/postinfo/summary



# taking stock at the end of this step
echo
echo Contents of /root/postinfo at the end of this STEP-999
ls -AlR /root/postinfo
echo End of "### STEP 999 ###"
echo
echo "###### THE END #####"
echo IMPORTANT: You must now copy all the files in /root/postinfo
echo to a safe location, preferably on a different drive or on
echo a removable backup medium.
echo " "
echo You will find a summary report of this procedure, in
echo /root/postinfo/summary
echo You will find the earlier version of summary \(if any\)
echo inside /root/postinfo/oldpostinfo.tar.gz
echo " "

#
echo "
#---------------------------------------------------------
#               WARNING  WARNING WARNING
#                shivalik (ver. 1.0)
# This script is being made accessible to you without any
# warranties or assurances about its performance or
# usability for any purpose. Be informed that you are using
# this script out of your own initiative and willingness,
# and at your own risk and peril.
# You will find the latest version of this script, and related
# information at: http://algolog.tripod.com/postlnx.htm
# Copyrights and all rights reserved by: 
# Dr. S. Parthasarathy (algolog@hd1.vsnl.net.in)
#--------------------------------------------------------
"