david/scripts-archive
david
/
scripts-archive
Archived
1
0
Fork 0
This repository has been archived on 2022-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-archive/clonebackup/start_backup.sh

63 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
#hosts="cluster1 cluster2 cluster3 cluster4 lic sanchoplan stereovideowall stereovideofloor video loadingapp"
hosts="testmachine"
pxeconfdir="/var/lib/tftpboot/pxelinux.cfg"
scriptpath="/srv/scripts"
# check for configfile
if [ -d $pxeconfdir ]; then
if [ -r $pxeconfdir/default ]; then
echo "default pxe config exists and is readable"
else
echo "default pxe config does not exist"
# create default pxe config
echo "creating config"
cp $scriptpath/tftpboot_default $pxeconfdir/default
fi
else
echo "there is no $pxeconfdir"
echo "are you sure you're running this script on your pxe server"
echo "exiting"
exit 1
fi
# cleaning up any previous mac address config files in pxeconfdir
echo "cleaning up previous mac address configurations in $pxeconfdir"
rm $pxeconfdir/00-* &> /dev/null
# starting actual backup process
set -- $hosts
for var in "$@"; do
echo "starting backup of $var"
# get mac for pxe config
macstring=$(cat $scriptpath/mac2hostname.lst | grep $var)
mac=${macstring:0:17}
correctmac="${mac//:/-}"
echo "mac of $var is $correctmac"
# create pxc config for $var
cp $scriptpath/tftpboot_mac $pxeconfdir/01-$correctmac
# remote reboot
echo "making the actual reboot of $var"
ssh -l Administrator $var shutdown -f -r -t 05
# sleep for 15 minutes
echo "sleeping for 10 minutes"
sleep 600
# remove temp pxe config for $var
echo "removing mac address configurations in $pxeconfdir"
rm $pxeconfdir/01-$correctmac
done
# end of script
echo "end of script, exiting"
exit 0