Back-up script(je)

Aangezien dat alles kapot kan, is het wel makkelijk dat je een back-up maakt van de software die je gebruikt. Aangezien ik geen zin heb omdat handmatig te doen heb ik hier een klein scriptje voor geschreven. Dit script maakt Incrementele back-ups en tar back-ups. Met crontab wordt het elke nacht om 3 uur uitgevoerd. Handig joh.

 

#!/bin/bash
# Backup script voor het backuppen naar een remote server op deze planeet.
# Created on 12-03-2017
# Author = Niels
# Version 012.9
# Key copyeren naar de remote server.
# ssh-keygen -t rsa
# ssh-copy-id user@123.45.56.78
# Crontabje :)
# 0  3    * * *   root    /usr/local/xnet/backup.sh
# service cron reload
#
LOG_FILE=/usr/local/xnet/backup.log
exec > >(tee -a ${LOG_FILE} )
#
##################Config optionsssss################################
TIME=`date +%b-%d-%y` # Datum toevoegen
SERVER=user@123.45.56.78 # Ssh`en remote username en ip.
REMOTEDES=/home/pd2lt/backup-packet # Remote directory
REMOTESYNC=/home/pd2lt/backup-packet/rsync # Remote rsync Directory
REMOVE=$(date --date="7 days ago" +%b-%d-%y) # filetjes ouder dan 7 dagen wegsmijten
# Tar File name
FILE=backup-xnet-$TIME.tar.gz # Backup file name
FILE2=backup-fbb-$TIME.tar.gz # Backup file name
FILE3=backup-conversd-$TIME.tar.gz # Backup file name
# Source pad.. Wat moet er gebackupd worden.
SRC=/usr/local/xnet # Watte.
SRC2=/usr/local/etc/ax25 # Watte.
SRC3=/usr/local/etc/conversd # Watte.
# Source pad. Local
DESDIR=/home/pd2lt/backup-packet # Waaro.
set $(date)
####################################################################
#
if test "$1" = "Sat" ; then
        # Let`s tar it
        tar -cpzf $DESDIR/$FILE $SRC
        tar -cpzf $DESDIR/$FILE2 $SRC2
        tar -cpzf $DESDIR/$FILE3 $SRC3
        #
        # Copy naar remote server, en vermoord filetje ouder dan 7 dagen.
        scp $DESDIR/$FILE $SERVER:$REMOTEDES && rm backup-xnet-$REMOVE.tar.gz
        scp $DESDIR/$FILE2 $SERVER:$REMOTEDES && rm backup-fbb-$REMOVE.tar.gz
        scp $DESDIR/$FILE3 $SERVER:$REMOTEDES && rm backup-conversd-$REMOVE.tar.gz
        #
else
        # Let`s sync it :)
        rsync -avz -e 'ssh -ax' $SRC $SERVER:$REMOTESYNC
        rsync -avz -e 'ssh -ax' $SRC2 $SERVER:$REMOTESYNC
        rsync -avz -e 'ssh -ax' $SRC3 $SERVER:$REMOTESYNC
        #
fi
# Mail backup log
mail -s "Backup log $TIME" pd2lt@emailadres.net < backup.log
echo "Script finished on $TIME"
rm -f backup.log
# Beetje info spuwen
df -h > /tmp/mail_report.log
free -m >> /tmp/mail_report.log
ps ax >> /tmp/mail_report.log
mail -s "disk and RAM report" pd2lt@emailadres.net < /tmp/mail_report.log

De laatste paar regels….. Het back.log bestand wordt gemaild en nog wat info over het systeem. Schijf gebruik, ram gebruik en de processen die draaien.

Start (X)Net/kissattach/slip at boot

I have written the startup script below so that all services are started. Now of course it is nice if this also happens when booting the server. First the start script.

#!/bin/sh
#
tmpfile="/tmp/$$.startax0.pts"
#
kissnetd -p 2 > "$tmpfile" &
#
sleep 2
#
attachthem () {
        read PTS1 PTS2
        echo "Starting PTS gekloot voor poort AX0 :)"
        kissattach -l $PTS1 ax0 192.168.1.113
	ifconfig ax0 netmask 255.255.255.0
        sleep 1
        sed -i "s,attach sdev3 kiss 3 1 115200 /dev/.*$,attach sdev3 kiss 3 1 115200 $PTS2," /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 $tmpfile | attachthem
rm $tmpfile
#
tmpfile="/tmp/$$.startax1.pts"
#
kissnetd -p 2 > "$tmpfile" &
#
sleep 2

attachthem () {
	read PTS1 PTS2
	echo "Starting PTS gekloot voor poort AX1 :)"
        kissattach -l $PTS1 ax1 192.168.1.113
        ifconfig ax1 netmask 255.255.255.0
        sleep 1
        sed -i "s,attach sdev4 kiss 4 1 115200 /dev/.*$,attach sdev4 kiss 4 1 115200 $PTS2," /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 $tmpfile | attachthem
rm $tmpfile
################## Klote slip link ###################################
XNET_DIR=/usr/local/xnet
LINIP=192.168.1.200     # LINUX-IP   address
XNET=192.168.1.201  # XNET  address
#
cd /usr/local/xnet
./dev &
#
sleep 2
#
attachthem () {
        read PTS1 PTS2
        echo "Starting PTS gekloot voor de slip link :)"
        slattach -s 38400 -p slip $PTS1 &
        sleep 1
        ifconfig sl0 $LINIP netmask 255.255.255.255 pointopoint $XNET mtu 236 up
        sleep 1
        sed -i "s,attach sdev6 slip 38400 /dev/.*$,attach sdev6 slip 38400 $PTS2," /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 /tmp/slip | attachthem
rm /tmp/slip

cd /usr/local/sbin
./ppconversd &
sleep 3
#
cd /usr/local/xnet
./rstatrxd /var/www/cgi-bin/postat/ &
sleep 2
#
  /sbin/modprobe netrom
  /usr/local/sbin/nrattach -i 192.168.1.113 -m 512 netrom
  /usr/local/sbin/nrattach -i 192.168.1.113 -m 512 netcon
  /usr/local/sbin/nrattach -i 192.168.1.113 -m 512 netbbs
# Init Netrom
   /usr/local/sbin/netromd -i -l -t 30
# Enable External Logons
  /usr/local/sbin/ax25d &
  /bin/sleep 2
# Start Mheard daemon
 /usr/local/sbin/mheardd
# start fbb
 /usr/local/sbin/fbb &
# Nu dan eindelijk Xnet
./linuxnet < /dev/tty2 > /dev/tty2 2>&1 &

Now I have created the following file in /etc/init.d with the name xnet.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          xnet
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Run /usr/local/xnet/xnet if it exist
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
        if [ -x /usr/local/xnet/xnet ]; then
                [ "$VERBOSE" != no ] && log_begin_msg "Running pi1lap)"
                /usr/local/xnet/xnet
                ES=$?
                [ "$VERBOSE" != no ] && log_end_msg $ES
                return $ES
        fi
}

case "$1" in
    start)
        do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

Now it has to be added.
update-rc.d xnet defaults
update-rc.d xnet enable

Well, reboot and see if everything is alright.