diff --git a/clonebackup/authorized_keys_root b/clonebackup/authorized_keys_root new file mode 100644 index 0000000..8bca8eb --- /dev/null +++ b/clonebackup/authorized_keys_root @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA9Kk/PiaCOR4D5wNv+0NI1tnYl81pdR9zEK4E997cGyWwDUhBFnlbbHJdBsH55xMDZV59pyVp4drFmt+QKplIPijSh5uJavjYENVtrPJHTrHOOd6B05rdruyaGxLBxOMLmwA/+e/U/Q0Nj17wHs4LCxr4oe+LlzaeSKLb2ZrSDhgrYc0CAQg58ISDRVUDXDXwaHlsJUAm1f3jHb4l6gVX8qhdJRT1aqjNtERG+uWJsZZIOIuHLrSqOhJvKif4xdc5fenVH0nkeAyrVZJJLrq33Bk/8i8z/ZiyM4/uUOfPwymI7aVNREXrEKTWG4GmgLugFDOyk563qqhljx97TmUJzQ== root@karlmoik diff --git a/clonebackup/clone.sh b/clonebackup/clone.sh new file mode 100755 index 0000000..0725062 --- /dev/null +++ b/clonebackup/clone.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# get mac address +net=192.168.19. +ifs="eth0 eth1 eth2 eth3 eth4" + +# get the configuration with ip +string=$(ip addr | grep "inet $net") + +set -- $ifs + +for var in "$@"; do + if [[ $string == "" ]]; then + echo "error: no interface configured to $net, exiting" + exit 1 + else + if [[ $string == *$var* ]]; then + macstring=$(ip addr show eth0 | grep ether) + fi + fi +done + +# get mac address +mac=${macstring:15:17} +#echo "MAC Address: $mac" + +# get the hostname from the list +hostnamestring=$(cat mac2hostname.lst | grep $mac) +hostname=${hostnamestring:18} +#echo "Hostname: $hostname" + +# generate imagename +imagename=$hostname"_$(echo $(date "+%d_%m_%C%y"))" +#echo "Imagename: $imagename" +echo $imagename + + +# starting clonezilla imaging process +/opt/drbl/sbin/ocs-sr -q2 -j2 -gs -z1 -i 0 -p reboot savedisk "$imagename" "sda" +# also possible "sda sdb" + +# end of script +exit 0 diff --git a/clonebackup/filebackup.conf b/clonebackup/filebackup.conf new file mode 100644 index 0000000..531be50 --- /dev/null +++ b/clonebackup/filebackup.conf @@ -0,0 +1,9 @@ +# shares to mount +# example: user@host:/smbshare/directory;password +# no symbols allowed in sharenames + +Administrator@192.168.19.20:/vrpack/VRProjects/;pentium4711 +#Administrator@192.168.19.20:/ssd\ \(s\)/Gigapixel/;pentium4711 +Administrator@192.168.19.20:/vrprojects/;pentium4711 +Administrator@192.168.19.100:/software/;pentium4711 + diff --git a/clonebackup/filebackup.sh b/clonebackup/filebackup.sh new file mode 100755 index 0000000..04dc85b --- /dev/null +++ b/clonebackup/filebackup.sh @@ -0,0 +1,98 @@ +#!/bin/bash + + # # # # # # # # # # # # # # # # + # # + # DeepSpace File Backup # + # v0.1 # + # david@socialnerds.org # + # # + # # # # # # # # # # # # # # # # + +## README SECTION +## +## nothing to read yet :-) +## +## + +# definitions +configfile="/srv/scripts/filebackup.conf" # use absolut path +mountpath="/mnt" +backuppath="/srv/filebackup" + +# gen timestamp +timestamp=$(echo $(date "+%d_%m_%C%y")) + +# am i root +if [ "$(whoami)" != "root" ]; then + echo "error: only root can do this" + exit 1; +fi + +# starting message with timestamp +echo +echo "info: starting deepspace filebackup on $timestamp" +echo + +# check if configfile is there and readable +if [ -r $configfile ]; then + # read configfile + i=1 + while read line; do + # check if first letter is a # + fletter=${line:0:1} + if [ -z "$line" ]; then + : + #echo "line $i is empty" + else + if [ $fletter == "#" ]; then + : + #echo "line $i a comment" + else + if [[ $line != *"@"*":"*";"* ]]; then + echo "error: line $i is not correct formated" + else + echo "info: reading config (line $i)" + userindex=`expr index "$line" @` + let userindex-- + user=${line:0:$userindex} + #echo "user: $user" + hostindex=`expr index "$line" :` + let hostindex-- + let userindex++ + host=${line:$userindex:$(($hostindex-$userindex))} + #echo "host: $host" + passindex=`expr index "$line" ";"` + share=${line:$(($hostindex+1)):$(($passindex-$hostindex-2))} + #echo "share: $share" + pass=${line:$passindex} + #echo "password: $pass" + + # check for mountpoint + if [ -d $mountpath/$i ]; then + echo "info: $mountpath/$i already exists" + else + mkdir -p $mountpath/$i + fi + echo "info: mounting $host$share to $mountpath/$i" + mount -t cifs -o username=$user,password=$pass //$host$share $mountpath/$i + # do backup + echo "info: creating destination folders" + mkdir -p $backuppath/$timestamp/$host$share/ + echo "info: starting rsync job" + rsync -r $mountpath/$i/* $backuppath/$timestamp/$host$share/ + # unmounting share + echo "info: unmounting $host$share" + umount $mountpath/$i + echo "info: backup done, please check if it's really there" + echo + fi + fi + fi + let i++ + done < $configfile +else + echo "error: no configfile found" + exit 1 +fi + +exit 0 diff --git a/clonebackup/mac2hostname.lst b/clonebackup/mac2hostname.lst new file mode 100644 index 0000000..1e1a9d1 --- /dev/null +++ b/clonebackup/mac2hostname.lst @@ -0,0 +1,15 @@ +b8:ac:6f:86:7d:49 dooku +00:22:19:2f:a6:fb loadingapp +00:22:19:14:69:ea cluster1 +00:22:19:14:6a:00 cluster2 +00:22:19:14:37:cf cluster3 +00:22:19:14:5f:bc cluster4 +00:22:19:14:6a:2f lic +#devicecontrol +#mosaik1 +00:22:19:14:6c:b5 mosaik2 +00:22:19:14:69:52 sanchoplan +00:22:19:14:5f:77 stereovideowall +00:22:19:14:6a:d2 stereovideofloor +00:22:19:11:e3:08 video +00:14:c2:5a:28:3e testmachine diff --git a/clonebackup/start_backup.sh b/clonebackup/start_backup.sh new file mode 100755 index 0000000..0dfcfb4 --- /dev/null +++ b/clonebackup/start_backup.sh @@ -0,0 +1,62 @@ +#!/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 diff --git a/clonebackup/tftpboot_default b/clonebackup/tftpboot_default new file mode 100644 index 0000000..2d65bd3 --- /dev/null +++ b/clonebackup/tftpboot_default @@ -0,0 +1,5 @@ +DEFAULT local + +LABEL local +MENU LABEL Local ^HDD +LOCALBOOT 0