#!/bin/sh
#
# HPC-286 GNU Host Backup Script. (C) Infra_HDC, 2001
# License is GPL, _no_ any kinds of warranty!
# Mail me to: askinfra@bagirra.net
#
# scriptmaker version
IBK_VERSION="0.02, 2001-11-26"
# the prefix
IBK_PREFIX="GHBS"
# current hostname
IBK_HOSTNAME=`hostname`
# current date
IBK_DATE=`date +%Y%m%d`
# current directory
IBK_PWD=`pwd`
# generated script filename
IBK_SCR_FILENAME="${IBK_PWD}/${IBK_HOSTNAME}-${IBK_DATE}.bak.sh"
# directory to store backups
IBK_TMPDIR="/mnt/home/infra/backup"
# output current settings
echo "The HPC-286 GHBS ScriptMaker. Version ${IBK_VERSION}. (C) Infra_HDC, 2001"
echo "Current datestamp is: ${IBK_DATE}" 
echo "Current directory is: ${IBK_PWD}"
echo "Script filename is: ${IBK_SCR_FILENAME}"
# create a hat of script
echo "#!/bin/sh" > ${IBK_SCR_FILENAME}
echo "# Generated by HPC-286 GHBS ScriptMaker. (C) Infra_HDC, 2001" >> ${IBK_SCR_FILENAME}
# echo "# ScriptMaker Version is ${IBK_VERSION}" >> ${IBK_SCR_FILENAME} 
echo "echo '${IBK_PREFIX}: HPC-286 GNU Host Backup Script. (C) Infra_HDC, 2001'" >> ${IBK_SCR_FILENAME}
echo "echo '${IBK_PREFIX}: ScriptMaker Version is: ${IBK_VERSION}'" >> ${IBK_SCR_FILENAME}
echo "echo '${IBK_PREFIX}: Current host is: ${IBK_HOSTNAME}'" >> ${IBK_SCR_FILENAME}
echo "echo '${IBK_PREFIX}: Current datestamp is: ${IBK_DATE}'" >> ${IBK_SCR_FILENAME}
echo "# this may be, if script loaded from diskette :)" >> ${IBK_SCR_FILENAME}
echo "# mount -t ext2 -o rw /dev/hda6 /mnt" >> ${IBK_SCR_FILENAME}
echo "cd /mnt" >> ${IBK_SCR_FILENAME}
IBK_ROOT="${IBK_HOSTNAME}-root-${IBK_DATE}.bak.tgz"
IBK_ROOTF="/mnt/root/${IBK_ROOT}"
echo "tar -czv --exclude ${IBK_ROOT} --file ${IBK_ROOTF} ." >> ${IBK_SCR_FILENAME}
echo "mount -t ext2 -o rw /dev/hda10 /mnt/home" >> ${IBK_SCR_FILENAME}
# !!! prepare temporary directory, be carefull !!!
echo "rm -rf ${IBK_TMPDIR}" >> ${IBK_SCR_FILENAME}
echo "mkdir ${IBK_TMPDIR}" >> ${IBK_SCR_FILENAME}
# moving root mountpoint backup from itself to temporary directory
echo "mv ${IBK_ROOTF} ${IBK_TMPDIR}" >> ${IBK_SCR_FILENAME}
echo "cd /mnt/home" >> ${IBK_SCR_FILENAME}
IBK_HOMEF="${IBK_TMPDIR}/${IBK_HOSTNAME}-home-${IBK_DATE}.bak.tgz"
echo "tar -czv --exclude ${IBK_HOSTNAME}-*-${IBK_DATE}.bak.tgz --file ${IBK_HOMEF} ." >> ${IBK_SCR_FILENAME}
# mount other partitions
echo "mount -t ext2 -o ro /dev/hda7 /mnt/var" >> ${IBK_SCR_FILENAME}
echo "mount -t ext2 -o ro /dev/hda8 /mnt/usr" >> ${IBK_SCR_FILENAME}
echo "mount -t ext2 -o ro /dev/hda9 /mnt/tmp" >> ${IBK_SCR_FILENAME}
echo "mount -t ext2 -o ro /dev/hda2 /mnt/boot" >> ${IBK_SCR_FILENAME}
# cycle of backup
IBK_OTHMP="var usr tmp boot"
# cycle of other mountpoints backup
for IBK_I in ${IBK_OTHMP}
  do
  echo "cd /mnt/${IBK_I}" >> ${IBK_SCR_FILENAME}
  echo "tar -czvf ${IBK_TMPDIR}/${IBK_HOSTNAME}-${IBK_I}-${IBK_DATE}.bak.tgz ." >> ${IBK_SCR_FILENAME}
done
echo "cd /" >> ${IBK_SCR_FILENAME}
echo "sync ; sync" >> ${IBK_SCR_FILENAME}
echo "echo '${IBK_PREFIX}: Backup to temporary directory (${IBK_TMPDIR}) is finished.'" >> ${IBK_SCR_FILENAME}
echo "Done. Copy this script file to /root directory before booting from diskette."
# End of Script
sync ; sync
