initial commit of file from CVS for smeserver-dar2 on Sat Sep 7 20:16:13 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:16:13 +10:00
parent dda5d4b557
commit 29314f312a
64 changed files with 7553 additions and 2 deletions

View File

@@ -0,0 +1,126 @@
#!/bin/sh
if [ ! -z "$1" ]
then
DCF=$1
else
/bin/echo "Syntax incorrect! Usage: dar2-backup dcf"
exit 0
fi
STATUS=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF status)
if [ "$STATUS" != 'enabled' ]
then
exit 1
fi
# Backup variables
STIME=$(/bin/date)
DAR="/usr/bin/dar"
EXPIRY=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Expiry)
ID=$(/sbin/e-smith/config get SystemName).$(/sbin/e-smith/config get DomainName)
MOUNT=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Mount) ## /media/usbdisk or /mnt/dar2
TARGET=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Target) ## //host/share
USERNAME=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Username)
PASSWORD=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Password)
VERBOSE=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Verbose)
VFSTYPE=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF VFSType) ## man mount
TODAY=$(/bin/date +%Y.%m.%d)
/bin/umount $MOUNT >/dev/null 2>&1
# mount
if [ "$MOUNT" == "/mnt/dar2" ]
then
MOUNT=$MOUNT/$DCF
# create mount dir
if [ ! -d $MOUNT ]
then
/bin/echo "Creating $MOUNT dir"
/bin/mkdir -p $MOUNT || exit 2
fi
/bin/echo "Connecting $MOUNT to $TARGET"
/bin/mount -t $VFSTYPE -o username=$USERNAME,password=$PASSWORD $TARGET $MOUNT || exit 3
else
/bin/echo "Connecting to $MOUNT"
/bin/mount $MOUNT || exit 4
fi
# expand job template
/bin/echo "Expanding /etc/dar2/$DCF template"
if [ -e "/etc/dar2/$DCF" ]
then
/bin/rm -f /etc/dar2/$DCF || exit 5
fi
/sbin/e-smith/expand-template /etc/dar2/dar2-backup $DCF ; /bin/mv /etc/dar2/dar2-backup /etc/dar2/$DCF || exit 6
# create destination dir
if [ ! -d $MOUNT/$ID/$DCF ]
then
/bin/echo "Creating destination /$ID/$DCF dir"
/bin/mkdir -p $MOUNT/$ID/$DCF || exit 7
fi
# zip and store db's
/bin/echo "Creating $MOUNT/$ID/$DCF/db.zip"
/usr/bin/zip -q -D $MOUNT/$ID/$DCF/db.zip /home/e-smith/db/*
# expire old backups
/bin/echo "Expiring old backups"
if [ "$EXPIRY" == "0" ]
then
/bin/rm -f $MOUNT/$ID/$DCF/*.dar
else
/usr/bin/find $MOUNT/$ID/$DCF/*.dar -type f -mtime +$EXPIRY -exec /bin/rm -f {} \; > /dev/null 2>&1
fi
# execute pre-backup event
/bin/echo "Executing pre-backup event"
/sbin/e-smith/signal-event pre-backup || exit 8
# state verbose
if [ "$VERBOSE" == "on" ]
then
/bin/echo "Verbose logging is on"
else
/bin/echo "Verbose logging is off"
fi
# perform dar backup
/bin/echo "Performing $DCF backup"
$DAR -B /etc/dar2/$DCF -c $MOUNT/$ID/$DCF/$TODAY || exit 9
# list archives
/bin/echo ""
/bin/echo "Listing $DCF archives on target:"
/bin/ls -l $MOUNT/$ID/$DCF/ || 10
# disk space usage
/bin/echo ""
/bin/echo "Total target disk space usage:"
/bin/df -h $MOUNT || 11
/bin/echo ""
# execute post-backup event
/bin/echo "Executing post-backup event"
/sbin/e-smith/signal-event post-backup || exit 12
# create log file
if [ "$VERBOSE" == "on" ]
then
/bin/echo "Creating /var/log/dar2/$ID/$DCF/$TODAY.log"
if [ ! -d /var/log/dar2/$ID/$DCF ]
then
/bin/mkdir -p /var/log/dar2/$ID/$DCF || exit 13
fi
$DAR -l $MOUNT/$ID/$DCF/$TODAY -as > /var/log/dar2/$ID/$DCF/$TODAY.log || exit 14
fi
# dismount
/bin/echo "Dismounting $MOUNT"
/bin/umount -l $MOUNT &
FTIME=$(/bin/date)
/bin/echo ""
/bin/echo "$STIME - backup started"
/bin/echo "$FTIME - backup finished"

View File

@@ -0,0 +1,82 @@
#!/bin/sh
# default variables
STIME=$(/bin/date)
DAR="/usr/bin/dar"
ID=$(/sbin/e-smith/config get SystemName).$(/sbin/e-smith/config get DomainName)
clear
/bin/echo "Enter your restore type: usb | network"
read TYPE
/bin/echo "Enter your job name:"
read DCF
/bin/echo "Enter your archive date to restore from: yyyy.mm.dd"
read DATE
if [ "$TYPE" == "usb" ]
then
# usb variables
/bin/echo "Enter your usb mount point: /media/usbdisk"
read MOUNT
/bin/echo "Connecting to $MOUNT"
/bin/mount $MOUNT
fi
if [ "$TYPE" == "network" ]
then
# ws variables
MOUNT=/mnt/dar2
/bin/echo "Enter your target name: //computername/sharename"
read TARGET
/bin/echo "Enter your username:"
read USERNAME
/bin/echo "Enter your password:"
read PASSWORD
/bin/echo "Enter your filesystem type: smbfs | cifs"
read VFSTYPE
MOUNT=$MOUNT/$DCF
# create mount dir
if [ ! -d $MOUNT ]
then
/bin/echo "Creating $MOUNT dir"
/bin/mkdir -p $MOUNT
fi
/bin/echo "Connecting $MOUNT to $TARGET"
/bin/mount -t $VFSTYPE -o username=$USERNAME,password=$PASSWORD $TARGET $MOUNT
fi
# check backup dir
if [ ! -d $MOUNT/$ID/$DCF ]
then
/bin/echo "Error locating /$ID/$DCF dir"
exit 7
fi
# execute pre-restore event
/bin/echo "Executing pre-restore event"
/sbin/e-smith/signal-event pre-restore
# perform dar restore
/bin/echo "Performing $DCF restore"
$DAR -x $MOUNT/$ID/$DCF/$DATE --fs-root / --noconf --no-warn --empty-dir --verbose
# dismount
/bin/echo "Dismounting $MOUNT"
/bin/umount -l $MOUNT &
FTIME=$(/bin/date)
/bin/echo "$STIME - restore started"
/bin/echo "$FTIME - restore finished"
# execute post restore events
/bin/echo "Executing post-upgrade & reboot"
/sbin/e-smith/signal-event post-upgrade;reboot

View File

@@ -0,0 +1,66 @@
#!/bin/sh
# install dar support into Midnight Commander
if [ ! -e /usr/share/mc/extfs/udar ]
then
cp -af /opt/dar2-mc/udar /usr/share/mc/extfs
cp -af /opt/dar2-mc/extfs.ini /usr/share/mc/extfs
cp -af /opt/dar2-mc/mc.ext /usr/share/mc
fi
# Prompt for job name
clear
/bin/echo "Enter your job name:"
read DCF
# Check job status
STATUS=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF status)
if [ "$STATUS" != 'enabled' ]
then
exit 0
fi
# variables
DAR="/usr/bin/dar"
ID=$(/sbin/e-smith/config get SystemName).$(/sbin/e-smith/config get DomainName)
MOUNT=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Mount)
TARGET=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Target)
USERNAME=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Username)
PASSWORD=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Password)
VFSTYPE=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF VFSType)
/bin/umount $MOUNT >/dev/null 2>&1
# mount
if [ "$MOUNT" == "/mnt/dar2" ]
then
MOUNT=$MOUNT/$DCF
# create mount dir
if [ ! -d $MOUNT ]
then
/bin/echo "Creating $MOUNT dir"
/bin/mkdir -p $MOUNT || exit 1
fi
/bin/echo "Connecting $MOUNT to $TARGET. Please wait..."
/bin/mount -t $VFSTYPE -o username=$USERNAME,password=$PASSWORD $TARGET $MOUNT || exit 2
else
/bin/echo "Connecting to $MOUNT. Please wait..."
/bin/mount $MOUNT || exit 3
fi
# check backup dir
if [ ! -d $MOUNT/$ID/$DCF ]
then
/bin/echo "Error locating /$ID/$DCF dir"
exit 4
fi
# run Midnight Commander
/bin/echo "Launching Midnight Commander"
mc $MOUNT/$ID/$DCF
# dismount
/bin/echo "Dismounting $MOUNT"
/bin/umount -l $MOUNT &
exit 5

View File

@@ -0,0 +1,92 @@
#!/bin/sh
if [ ! -z "$1" ]
then
DCF=$1
else
/bin/echo "Syntax incorrect! Usage: dar2-restore dcf"
exit 0
fi
STATUS=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF status)
if [ "$STATUS" != 'enabled' ]
then
exit 1
fi
STIME=$(/bin/date)
DAR="/usr/bin/dar"
# Backup variables
ID=$(/sbin/e-smith/config get SystemName).$(/sbin/e-smith/config get DomainName)
MOUNT=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Mount)
TARGET=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Target)
USERNAME=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Username)
PASSWORD=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF Password)
VFSTYPE=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop $DCF VFSType)
# Restore variables
DATE=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop Restore.$DCF Date)
DR=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop Restore.$DCF DR)
RESTORETO=$(/sbin/e-smith/db /home/e-smith/db/dar2 getprop Restore.$DCF RestoreTo)
/bin/umount $MOUNT >/dev/null 2>&1
# mount
if [ "$MOUNT" == "/mnt/dar2" ]
then
MOUNT=$MOUNT/$DCF
# create mount dir
if [ ! -d $MOUNT ]
then
/bin/echo "Creating $MOUNT dir"
/bin/mkdir -p $MOUNT || exit 2
fi
/bin/echo "Connecting $MOUNT to $TARGET"
/bin/mount -t $VFSTYPE -o username=$USERNAME,password=$PASSWORD $TARGET $MOUNT || exit 3
else
/bin/echo "Connecting to $MOUNT"
/bin/mount $MOUNT || exit 4
fi
# expand job template
/bin/echo "Expanding /etc/dar2/$DCF template"
if [ -e "/etc/dar2/$DCF" ]
then
/bin/rm -f /etc/dar2/$DCF || exit 5
fi
/sbin/e-smith/expand-template /etc/dar2/dar2-restore $DCF ; /bin/mv /etc/dar2/dar2-restore /etc/dar2/$DCF || exit 6
# check backup dir
if [ ! -d $MOUNT/$ID/$DCF ]
then
/bin/echo "Error locating /$ID/$DCF dir"
exit 7
fi
# execute pre-restore event
if [ "$DR" == "Enabled" ]
then
/bin/echo "Executing pre-restore event"
/sbin/e-smith/signal-event pre-restore || exit 8
fi
# perform dar restore
/bin/echo "Performing $DCF restore"
$DAR -x $MOUNT/$ID/$DCF/$DATE -B /etc/dar2/$DCF || exit 9
# dismount
/bin/echo "Dismounting $MOUNT"
/bin/umount -l $MOUNT &
FTIME=$(/bin/date)
/bin/echo "$STIME - restore started"
/bin/echo "$FTIME - restore finished"
if [ "$DR" == "Enabled" ]
then
/bin/echo "To finish your disaster recovery restore, please run:"
/bin/echo ""
/bin/echo "signal-event post-upgrade ; signal-event reboot"
fi