initial commit of a *whole bunch* of old Egressive shell scripts, used to make many people redundant.
This commit is contained in:
commit
43e0f5b59e
329 changed files with 31937 additions and 0 deletions
192
egrdbackup-usb/egrdbackup
Executable file
192
egrdbackup-usb/egrdbackup
Executable file
|
@ -0,0 +1,192 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# egrdbackup
|
||||
#
|
||||
# (c) 2006 Egressive Limited
|
||||
# Backup script using rdiff-backup
|
||||
# by rob@egressive.com
|
||||
# modified by dave@egressive.com 20060920
|
||||
# modified rob@egressive.com 20061206 moved config items into seperate .conf file
|
||||
#
|
||||
##
|
||||
# Description - egrdbackup performs one task:
|
||||
#
|
||||
# Performs incremental backups of designated directory
|
||||
# hierarchy or backup set (minus any exclusions) into a designated
|
||||
# backup directory.
|
||||
#
|
||||
# The current view of the data at any time will reflect the most
|
||||
# recent state of all the files in the backup set. Diffs for
|
||||
# older versions of all files are stored in hidden directories.
|
||||
# Older versions of any file can be recovered using rdiff-backup directly.
|
||||
#
|
||||
# For example, to recover a backup of the directory (and contents) of
|
||||
# /home/operations from 4 days ago, where the backup directory is /backups, run:
|
||||
#
|
||||
# rdiff-backup -r 4D /backups/home/operations/ /home/operations/recovered-$(date "+%Y-%m-%d")
|
||||
#
|
||||
##
|
||||
#
|
||||
# Default Settings
|
||||
#
|
||||
DEBUG=false
|
||||
#
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "Default Settings"
|
||||
fi
|
||||
#
|
||||
RDIFF_COMMAND=`which rdiff-backup`
|
||||
MAIL_COMMAND=`which mail`
|
||||
DF_COMMAND=`which df`
|
||||
GREP_COMMAND=`which grep`
|
||||
TAIL_COMMAND=`which tail`
|
||||
NICE_COMMAND=`which nice`
|
||||
HEAD_COMMAND=`which head`
|
||||
CAT_COMMAND=`which cat`
|
||||
DIRNAME_COMMAND=`which dirname`
|
||||
BASENAME_COMMAND=`which basename`
|
||||
MAIL_TO=root # temporary - overridden in CONF_FILE
|
||||
#
|
||||
#
|
||||
#EGRD_ROOT=/etc/egscripts/egrdbackup
|
||||
EGRD_ROOT=`$DIRNAME_COMMAND $0`
|
||||
EGRD_SCRIPT=`$BASENAME_COMMAND $0`
|
||||
# config file
|
||||
CONF_FILE=$EGRD_ROOT/$EGRD_SCRIPT.conf
|
||||
# name of file to run before and after rdiff-backup runs - for example an initial rsync or usb mount
|
||||
INITIAL_CMD_FILE="initial.sh"
|
||||
POST_CMD_FILE="postrun.sh"
|
||||
#
|
||||
INITIAL_CMD_FILE_OK="true"
|
||||
#
|
||||
# initialise end status
|
||||
BACKUP_STATUS="[SUCCESS]"
|
||||
#
|
||||
# Get local configuration
|
||||
#
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "Get Local Settings"
|
||||
fi
|
||||
if [ -x $CONF_FILE ] ; then
|
||||
. $CONF_FILE
|
||||
else
|
||||
$CAT_COMMAND $LOGFILE | $MAIL_COMMAND -s "[ERROR] Could not find config file for $SERVERNAME backup" $MAIL_TO
|
||||
exit 1
|
||||
fi
|
||||
# logfile
|
||||
LOGFILE=/var/log/$EGRD_LOGNAME.log # use logrotate to manage logs
|
||||
#
|
||||
#
|
||||
##
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "Remove Older versions"
|
||||
fi
|
||||
#
|
||||
# You will need a --force the first time you run, or if you clear out the $RDIFF_DEST
|
||||
# directory at any stage. Probably safer not to use it normally.
|
||||
#
|
||||
# check to see if the default rdiff revision directory is in place - if so, don't force
|
||||
#
|
||||
if [ "$RDIFF_FORCE" == "true" ] ; then
|
||||
RDIFF_FORCE_ARG=" --force "
|
||||
fi
|
||||
#
|
||||
#
|
||||
# If an initial command file exists (say to do an rsync first)
|
||||
#
|
||||
if [ -x $EGRD_ROOT/$INITIAL_CMD_FILE ] ; then
|
||||
. $EGRD_ROOT/$INITIAL_CMD_FILE
|
||||
fi
|
||||
#
|
||||
if ! [ $INITIAL_CMD_FILE_OK == "true" ]
|
||||
then
|
||||
BACKUP_STATUS="[ERROR]"
|
||||
BACKUP_ERROR=" | Error during initial setup"
|
||||
echo "Fatal error while running initial.sh" >> $LOGFILE 2>> $LOGFILE
|
||||
$CAT_COMMAND $LOGFILE | $MAIL_COMMAND -s "$BACKUP_STATUS $SERVERNAME backup $BACKUP_ERROR" $MAIL_TO >> $LOGFILE 2>> $LOGFILE
|
||||
echo "Email sent to $MAIL_TO" >> $LOGFILE
|
||||
echo "Script complete" >> $LOGFILE 2>> $LOGFILE
|
||||
echo "" >> $LOGFILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -d $RDIFF_DEST/rdiff-backup-data ; then
|
||||
if test -n $RDIFF_DAYS_OF_REVISIONS ; then
|
||||
#
|
||||
echo "++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
|
||||
echo " Deleting revisions older than $RDIFF_DAYS_OF_REVISIONS days " >> $LOGFILE
|
||||
echo "++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
|
||||
# run delete command...
|
||||
echo "Running command: $NICE_COMMAND $RDIFF_COMMAND --force --remove-older-than ${RDIFF_DAYS_OF_REVISIONS}D $RDIFF_DEST" >> $LOGFILE
|
||||
if ! $NICE_COMMAND $RDIFF_COMMAND --force --remove-older-than ${RDIFF_DAYS_OF_REVISIONS}D $RDIFF_DEST >> $LOGFILE 2>> $LOGFILE ; then
|
||||
if ! $TAIL_COMMAND -2 $LOGFILE | $GREP_COMMAND "No increments older" > /dev/null 2>> $LOGFILE ; then
|
||||
BACKUP_STATUS="[ERROR]"
|
||||
BACKUP_ERROR=" | Error deleting revisions"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
#
|
||||
##
|
||||
ALL_RDIFF_EXCLUDES=""
|
||||
if [ -n "$RDIFF_EXCLUDES" ] ; then
|
||||
for i in $RDIFF_EXCLUDES ; do
|
||||
ALL_RDIFF_EXCLUDES=$ALL_RDIFF_EXCLUDES" --exclude $i "
|
||||
done
|
||||
fi
|
||||
#
|
||||
# Start Rdiff-backup!
|
||||
#
|
||||
# make sure log file exists
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "Start backup"
|
||||
fi
|
||||
touch $LOGFILE
|
||||
DATE=`date`
|
||||
echo "+++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
|
||||
echo " Starting backup ($DATE) " >> $LOGFILE
|
||||
echo "+++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
|
||||
echo "Running command: $NICE_COMMAND $RDIFF_COMMAND $RDIFF_ARGS $ALL_RDIFF_EXCLUDES $RDIFF_SRC $RDIFF_DEST " >> $LOGFILE
|
||||
if ! $NICE_COMMAND $RDIFF_COMMAND $RDIFF_FORCE_ARG $RDIFF_ARGS $ALL_RDIFF_EXCLUDES $RDIFF_SRC $RDIFF_DEST \
|
||||
>> $LOGFILE 2>> $LOGFILE ; then
|
||||
echo "Error Code - rdiff-backup returned: $?" >> $LOGFILE
|
||||
fi
|
||||
if ! $TAIL_COMMAND -3 $LOGFILE | $GREP_COMMAND "Errors 0" > /dev/null 2>> $LOGFILE
|
||||
then
|
||||
BACKUP_STATUS="[ERROR]"
|
||||
BACKUP_ERROR=$BACKUP_ERROR" | Error during backup"
|
||||
fi
|
||||
#
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "============================="
|
||||
tail -10 $LOGFILE
|
||||
echo "============================="
|
||||
fi
|
||||
#
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "Log and email out results"
|
||||
fi
|
||||
#
|
||||
echo "File system usage:" >> $LOGFILE
|
||||
$DF_COMMAND -h >> $LOGFILE 2>> $LOGFILE
|
||||
#
|
||||
if [ $DEBUG == "true" ] ; then
|
||||
echo "Finish"
|
||||
fi
|
||||
#
|
||||
DATE=`date`
|
||||
echo "+++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
|
||||
echo " Completed backup ($DATE) " >> $LOGFILE
|
||||
echo "+++++++++++++++++++++++++++++++++++++++++++" >> $LOGFILE
|
||||
#
|
||||
#
|
||||
# If a post command file exists (say to unmount a usb drive)
|
||||
#
|
||||
if [ -x $EGRD_ROOT/$POST_CMD_FILE ] ; then
|
||||
. $EGRD_ROOT/$POST_CMD_FILE
|
||||
fi
|
||||
#
|
||||
$CAT_COMMAND $LOGFILE | $MAIL_COMMAND -s "$BACKUP_STATUS $SERVERNAME backup $BACKUP_ERROR" $MAIL_TO >> $LOGFILE 2>> $LOGFILE
|
||||
echo "Email sent to $MAIL_TO" >> $LOGFILE
|
||||
echo "Script complete" >> $LOGFILE 2>> $LOGFILE
|
||||
echo "" >> $LOGFILE
|
8
egrdbackup-usb/egrdbackup-cron
Executable file
8
egrdbackup-usb/egrdbackup-cron
Executable file
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# egbackup, copyright 2005 egressive limited, www.egressive.com
|
||||
#
|
||||
# run system backups
|
||||
#
|
||||
# daily - at 2:30 am, mon-sun
|
||||
30 2 * * * root /etc/egscripts/egrdbackup/egrdbackup
|
||||
|
39
egrdbackup-usb/egrdbackup.conf
Executable file
39
egrdbackup-usb/egrdbackup.conf
Executable file
|
@ -0,0 +1,39 @@
|
|||
# Configuration Variables
|
||||
#
|
||||
# Name of the server for the subject of the success/ failure
|
||||
#SERVERNAME="jimbo.egressive.com"
|
||||
SERVERNAME="USB intranet.tradeaid.co.nz"
|
||||
#
|
||||
EGRD_LOGNAME="egrdbackup-usb"
|
||||
#
|
||||
# Source and destination directories for the backup
|
||||
RDIFF_SRC="/"
|
||||
#
|
||||
#RDIFF_DEST="root@hostname::/storage/backups/this_server"
|
||||
#RDIFF_DEST="/storage/backups"
|
||||
RDIFF_DEST="/mnt"
|
||||
#
|
||||
RDIFF_ARGS="--print-statistics --include-symbolic-links --exclude-sockets --exclude-fifos"
|
||||
#
|
||||
# Age of oldest revisions
|
||||
RDIFF_DAYS_OF_REVISIONS="90" # 30 = 30 Days
|
||||
#
|
||||
# Do we need to force a backup (e.g. due to an error)
|
||||
# true or false
|
||||
RDIFF_FORCE=false
|
||||
#
|
||||
#Directories to exclude from backup - space separated list
|
||||
RDIFF_EXCLUDES="/proc /tmp /var/tmp /mnt /sys /dev/bus /media /mnt /storage "
|
||||
#
|
||||
# Check to see if this is a local backup (ie no :: in the destination).
|
||||
# Local backups need to exclude the destination from being backup up ;-)
|
||||
#
|
||||
if ! [ `echo $RDIFF_EXCLUDES | grep -c ":"` ]
|
||||
then
|
||||
RDIFF_EXCLUDES = $RDIFF_EXCLUDES" --exclude $RDIFF_DEST "
|
||||
fi
|
||||
#
|
||||
# mail account for sending success/ failure messages
|
||||
MAIL_TO="Graeme.Sleeman@tradeaid.org.nz,support@egressive.com"
|
||||
#
|
||||
##
|
42
egrdbackup-usb/egrdbackup.conf.example
Executable file
42
egrdbackup-usb/egrdbackup.conf.example
Executable file
|
@ -0,0 +1,42 @@
|
|||
# Configuration Variables
|
||||
#
|
||||
# Name of the server for the subject of the success/ failure
|
||||
#SERVERNAME="jimbo.egressive.com"
|
||||
SERVERNAME=""
|
||||
#
|
||||
# Change this for multiple egrdbackups on the same server (eg USB and local)
|
||||
#EGRD_LOGNAME="egrdbackup-usb"
|
||||
EGRD_LOGNAME="egrdbackup"
|
||||
#
|
||||
# Source and destination directories for the backup
|
||||
RDIFF_SRC="/"
|
||||
#
|
||||
#RDIFF_DEST="root@hostname::/storage/backups/this_server"
|
||||
#RDIFF_DEST="/storage/backups"
|
||||
#RDIFF_DEST="/mnt"
|
||||
RDIFF_DEST=""
|
||||
#
|
||||
RDIFF_ARGS="--print-statistics --include-symbolic-links --exclude-sockets --exclude-fifos"
|
||||
#
|
||||
# Age of oldest revisions
|
||||
RDIFF_DAYS_OF_REVISIONS="30" # 30 = 30 Days
|
||||
#
|
||||
# Do we need to force a backup (e.g. due to an error)
|
||||
# true or false
|
||||
RDIFF_FORCE=false
|
||||
#
|
||||
#Directories to exclude from backup - space separated list
|
||||
RDIFF_EXCLUDES="/proc /tmp /var/tmp /mnt /sys /dev/bus /media /storage /var/cache/apt/archives"
|
||||
#
|
||||
# Check to see if this is a local backup (ie no :: in the destination).
|
||||
# Local backups need to exclude the destination from being backup up ;-)
|
||||
#
|
||||
if ! [ `echo $RDIFF_EXCLUDES | grep -c ":"` ]
|
||||
then
|
||||
RDIFF_EXCLUDES = $RDIFF_EXCLUDES" --exclude $RDIFF_DEST "
|
||||
fi
|
||||
#
|
||||
# mail account for sending success/ failure messages
|
||||
MAIL_TO="support@egressive.com"
|
||||
#
|
||||
##
|
35
egrdbackup-usb/initial.sh
Executable file
35
egrdbackup-usb/initial.sh
Executable file
|
@ -0,0 +1,35 @@
|
|||
#/bin/bash
|
||||
#
|
||||
# This script runs before the main rdiffbackup script
|
||||
# useful for mounting USB drives
|
||||
#
|
||||
#
|
||||
#
|
||||
POSSIBLE_USB_DRIVES="/dev/sdc1 /dev/sdd1"
|
||||
MOUNT_POINT="/mnt"
|
||||
USB_DRIVE="nodrivefound"
|
||||
#
|
||||
#
|
||||
for i in $POSSIBLE_USB_DRIVES
|
||||
do
|
||||
if udevinfo --query=name --name $i > /dev/null 2>> $LOGFILE
|
||||
then
|
||||
USB_DRIVE=$i
|
||||
fi
|
||||
done
|
||||
if [ $USB_DRIVE == "nodrivefound" -o $MOUNT_POINT"xxx" == "xxx" ]
|
||||
then
|
||||
echo "ERROR - Mount point or drive device not defined in config file or drive device not found" >> $LOGFILE 2>> $LOGFILE
|
||||
INITIAL_CMD_FILE_OK="false"
|
||||
elif ! mount | grep $USB_DRIVE > /dev/null
|
||||
then
|
||||
if ! mount $USB_DRIVE $MOUNT_POINT
|
||||
then
|
||||
echo "ERROR - Couldn't mount USB Drive" >> $LOGFILE 2>> $LOGFILE
|
||||
INITIAL_CMD_FILE_OK="false"
|
||||
fi
|
||||
else
|
||||
echo "WARNING - $USB_DRIVE already mounted" >> $LOGFILE 2>> $LOGFILE
|
||||
fi
|
||||
|
||||
#echo $INITIAL_CMD_FILE_OK
|
34
egrdbackup-usb/initial.sh.example
Executable file
34
egrdbackup-usb/initial.sh.example
Executable file
|
@ -0,0 +1,34 @@
|
|||
#/bin/bash
|
||||
#
|
||||
# This script runs before the main rdiffbackup script
|
||||
# useful for mounting USB drives
|
||||
#
|
||||
#
|
||||
#
|
||||
POSSIBLE_USB_DRIVES="/dev/sdc1 /dev/sdd1"
|
||||
MOUNT_POINT="/mnt"
|
||||
USB_DRIVE="unknowndrive"
|
||||
#
|
||||
#
|
||||
for i in $POSSIBLE_USB_DRIVES
|
||||
do
|
||||
if udevinfo --query=name --name $i > /dev/null 2>> $LOGFILE
|
||||
then
|
||||
USB_DRIVE=$i
|
||||
fi
|
||||
done
|
||||
if [ $USB_DRIVE == "unknowndrive" -o $MOUNT_POINT"xxx" == "xxx" ]
|
||||
then
|
||||
echo "ERROR - Mount point or drive device not defined in config file or drive device not found" >> $LOGFILE 2>> $LOGFILE
|
||||
INITIAL_CMD_FILE_OK="false"
|
||||
elif ! mount | grep $USB_DRIVE > /dev/null
|
||||
then
|
||||
if ! mount $USB_DRIVE $MOUNT_POINT
|
||||
then
|
||||
echo "ERROR - Couldn't mount USB Drive" >> $LOGFILE 2>> $LOGFILE
|
||||
INITIAL_CMD_FILE_OK="false"
|
||||
fi
|
||||
else
|
||||
echo "WARNING - $USB_DRIVE already mounted" >> $LOGFILE 2>> $LOGFILE
|
||||
INITIAL_CMD_FILE_OK="false"
|
||||
fi
|
34
egrdbackup-usb/initial.sh.example-usb
Executable file
34
egrdbackup-usb/initial.sh.example-usb
Executable file
|
@ -0,0 +1,34 @@
|
|||
#/bin/bash
|
||||
#
|
||||
# This script runs before the main rdiffbackup script
|
||||
# useful for mounting USB drives
|
||||
#
|
||||
#
|
||||
#
|
||||
POSSIBLE_USB_DRIVES="/dev/sdc1 /dev/sdd1"
|
||||
MOUNT_POINT="/mnt"
|
||||
USB_DRIVE=""
|
||||
#
|
||||
#
|
||||
for i in $POSSIBLE_USB_DRIVES
|
||||
do
|
||||
if udevinfo --query=name --name $i
|
||||
then
|
||||
USB_DRIVE=$i
|
||||
fi
|
||||
done
|
||||
if [ $USB_DRIVE"xxx" == "xxx" -o $MOUNT_POINT"xxx" == "xxx" ]
|
||||
then
|
||||
echo "ERROR - Mount point or drive device not defined in config file or drive device not found" >> $LOGFILE 2>> $LOGFILE
|
||||
fi
|
||||
#
|
||||
if ! mount | grep $USB_DRIVE > /dev/null
|
||||
then
|
||||
if ! mount $USB_DRIVE $MOUNT_POINT
|
||||
then
|
||||
echo "ERROR - Couldn't mount USB Drive" >> $LOGFILE 2>> $LOGFILE
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "WARNING - $USB_DRIVE already mounted" >> $LOGFILE 2>> $LOGFILE
|
||||
fi
|
7
egrdbackup-usb/logrotate.d/egrdbackup
Normal file
7
egrdbackup-usb/logrotate.d/egrdbackup
Normal file
|
@ -0,0 +1,7 @@
|
|||
/var/log/egrdbackup.log {
|
||||
daily
|
||||
missingok
|
||||
rotate 7
|
||||
compress
|
||||
notifempty
|
||||
}
|
29
egrdbackup-usb/postrun.sh
Executable file
29
egrdbackup-usb/postrun.sh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#/bin/bash -x
|
||||
#
|
||||
# This script runs before the main rdiffbackup script
|
||||
# useful for mounting USB drives
|
||||
#
|
||||
# returns
|
||||
# nothing if successful
|
||||
# 1 = error on umount command
|
||||
# 2 = parameters not defined
|
||||
# 3 = no file system mounted
|
||||
#
|
||||
#
|
||||
if [ $MOUNT_POINT"xxx" == "xxx" ]
|
||||
then
|
||||
echo "ERROR - Mount point not defined in initial.sh file" >> $LOGFILE
|
||||
fi
|
||||
#
|
||||
if mount | grep $MOUNT_POINT > /dev/null
|
||||
then
|
||||
if ! umount $MOUNT_POINT
|
||||
then
|
||||
echo "ERROR - Couldn't unmount $MOUNT_POINT" >> $LOGFILE
|
||||
|
||||
fi
|
||||
else
|
||||
echo "ERROR - no file system on $MOUNT_POINT" >> $LOGFILE
|
||||
|
||||
fi
|
||||
|
29
egrdbackup-usb/postrun.sh.example-usb
Executable file
29
egrdbackup-usb/postrun.sh.example-usb
Executable file
|
@ -0,0 +1,29 @@
|
|||
#/bin/bash -x
|
||||
#
|
||||
# This script runs before the main rdiffbackup script
|
||||
# useful for mounting USB drives
|
||||
#
|
||||
# returns
|
||||
# nothing if successful
|
||||
# 1 = error on umount command
|
||||
# 2 = parameters not defined
|
||||
# 3 = no file system mounted
|
||||
#
|
||||
#
|
||||
if [ $MOUNT_POINT"xxx" == "xxx" ]
|
||||
then
|
||||
echo "ERROR - Mount point not defined in initial.sh file" >> $LOGFILE
|
||||
fi
|
||||
#
|
||||
if mount | grep $MOUNT_POINT > /dev/null
|
||||
then
|
||||
if ! umount $MOUNT_POINT
|
||||
then
|
||||
echo "ERROR - Couldn't unmount $MOUNT_POINT" >> $LOGFILE
|
||||
|
||||
fi
|
||||
else
|
||||
echo "ERROR - no file system on $MOUNT_POINT" >> $LOGFILE
|
||||
|
||||
fi
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue