Updated README.md with changes

Updated data command in scripts
Updated folders for nasbackup.sh
This commit is contained in:
Matthew McKinnon 2016-03-28 18:55:16 +10:00
parent 9c7ee5aa5e
commit 0aaa55b761
4 changed files with 30 additions and 41 deletions

View File

@ -8,11 +8,12 @@ To send emails the sendEmail package is required
Change the following lines in scripts that send emails Change the following lines in scripts that send emails
Edit the following for emails: MAILFROM is set to determine the server name and domain name for the server and generate and email for it to determine where the email is coming from. This can be changed to specify an email address or you can leave it to generate one.
<pre><code> <pre><code>
MAILTO="support@comprofix.com" MAILTO=user@example.com
SMTP=mail.comprofix.com SMTP=mail.example.com
MAILFROM="support@comprofix.com" MAILFROM=$(hostaname)@$(dnsdomainname)
</code></pre> </code></pre>
#### 00logwatch #### 00logwatch
@ -27,7 +28,7 @@ ln -s $(pwd)/00logwatch /etc/cron.daily
#### check_updates_deb_sh #### check_updates_deb_sh
This script checks for updates on your debian system. If any updates are found it will download them ready for Installation and an email will be sent to an email address specified This script checks for updates on your Debian based systems. If any updates are found it will download them ready for Installation and an email will be sent to an email address specified
<b>Installation</b> <b>Installation</b>
<pre><code> <pre><code>

View File

@ -16,12 +16,11 @@
MAILTO="support@comprofix.com" MAILTO="support@comprofix.com"
SMTP=mail.comprofix.com SMTP=mail.comprofix.com
MAILFROM="$(hostname)@$(dnsdomainname)"
AUTOUPDATE="no" AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log" LOGFILE="/var/log/server_maint.log"
THISSERVER=`hostname --fqdn` THISSERVER=$(hostname -f)
MAILFROM="$(hostname)@$(dnsdomainname)"
# #
# End of user configuration section # End of user configuration section
@ -35,30 +34,30 @@ DASHES2="=======================================================================
if [ $(id -u) -ne 0 ] if [ $(id -u) -ne 0 ]
then then
echo "ur not root bro" echo "You need to be root to run this script."
exit 1 exit 1
fi fi
startlogging() { startlogging() {
echo $DASHES2 >> $LOGFILE echo $DASHES2 >> $LOGFILE
echo "$0 started running at `date`" >> $LOGFILE echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE echo $DASHES2 >> $LOGFILE
} }
stoplogging() { stoplogging() {
echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE echo $DASHES >> $LOGFILE
} }
check_return() { check_return() {
if [ "$?" -ne "0" ] if [ "$?" -ne "0" ]
then then
echo "`date` [ERROR] $1 failed to run" >> $LOGFILE echo "$(date) [ERROR] $1 failed to run" >> $LOGFILE
send_error_email $1 send_error_email $1
stoplogging stoplogging
exit 1 exit 1
fi fi
echo "`date` [SUCCESS] $1 ran without error" >> $LOGFILE echo "$(date) [SUCCESS] $1 ran without error" >> $LOGFILE
} }
send_error_email() { send_error_email() {
@ -72,7 +71,7 @@ Whilst running the update script ($0) on $THISSERVER there was a problem.
The server has the following network interfaces configured ${SERVERADDS[@]}. The server has the following network interfaces configured ${SERVERADDS[@]}.
Please log in via ssh (e.g. ssh root@${IPADDR[0]}) and check the log file: Please log in via ssh (e.g. ssh root@$(hostname -f)) and check the log file:
vim $LOGFILE vim $LOGFILE
@ -122,7 +121,7 @@ fi
if [[ -z $PACKAGES_TO_BE_UPGRADED ]] if [[ -z $PACKAGES_TO_BE_UPGRADED ]]
then then
echo "`date` [MESSAGE] No packages need updating." >> $LOGFILE echo "$(date) [MESSAGE] No packages need updating." >> $LOGFILE
else else
echo " echo "
@ -134,7 +133,7 @@ $PACKAGES_TO_BE_UPGRADED
The server has the following network interfaces configured ${SERVERADDS[@]}. The server has the following network interfaces configured ${SERVERADDS[@]}.
To update the server log in via ssh (e.g. ssh root@${IPADDR[0]}) and run the following command: To update the server log in via ssh (e.g. ssh root@$(hostname -f)) and run the following command:
apt-get upgrade apt-get upgrade
@ -144,7 +143,7 @@ Regards. " >/tmp/servermail.msg
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)" sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] server may need some updates applied" -m "$(cat /tmp/servermail.msg)"
echo "`date` [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE echo "$(date) [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
fi fi
stoplogging stoplogging

View File

@ -7,13 +7,13 @@ MAILFROM="$(hostname)@$(dnsdomainname)"
startlogging() { startlogging() {
echo $DASHES2 >> $LOGFILE echo $DASHES2 >> $LOGFILE
echo "$0 started running at `date`" >> $LOGFILE echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE echo $DASHES2 >> $LOGFILE
} }
stoplogging() { stoplogging() {
echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE echo $DASHES >> $LOGFILE
} }
@ -36,12 +36,12 @@ do
let space=`df -Pk $i | grep -v ^File | awk '{printf ("%i", $5) }'` let space=`df -Pk $i | grep -v ^File | awk '{printf ("%i", $5) }'`
if [ $space -le 89 ] if [ $space -le 89 ]
then then
echo "`date` [MESSAGE] Disk space usage on $i acceptable. $space% currently in use." >> $LOGFILE echo "$(date) [MESSAGE] Disk space usage on $i acceptable. $space% currently in use." >> $LOGFILE
fi fi
if [ $space -ge 90 ] if [ $space -ge 90 ]
then then
echo "`date` [WARNING] $i is running out of disk space. $space% currently in use." >> $LOGFILE echo "$(date) [WARNING] $i is running out of disk space. $space% currently in use." >> $LOGFILE
echo " echo "
Hello, Hello,
@ -54,20 +54,10 @@ See the logfile for more info: vim $LOGFILE
Regards, " >/tmp/diskalertmail.msg Regards, " >/tmp/diskalertmail.msg
cat /tmp/diskalertmail.msg | sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] is running out of disk space" cat /tmp/diskalertmail.msg | sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] is running out of disk space"
echo "`date` [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE echo "$(date) [MESSAGE] Running out of disk space email sent to $MAILTO" >> $LOGFILE
fi fi
done done
stoplogging stoplogging

View File

@ -15,17 +15,16 @@ N_DAYS=7
LOG=$LOGFOLDER/backuplog-`date +%d-%m-%Y`.log LOG=$LOGFOLDER/backuplog-`date +%d-%m-%Y`.log
echo "****************************************************************" > $LOG 2>&1 echo "****************************************************************" > $LOG 2>&1
echo " Start Backup `date` " >> $LOG 2>&1 echo " Start Backup $(data) " >> $LOG 2>&1
echo "****************************************************************" >> $LOG 2>&1 echo "****************************************************************" >> $LOG 2>&1
#rsync -urtlPO --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1 #rsync -urtlPO --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1 rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOG 2>&1
echo "****************************************************************" >> $LOG 2>&1 echo "****************************************************************" >> $LOG 2>&1
echo " Finished Backup `date` " >> $LOG 2>&1 echo " Finished Backup $(date) " >> $LOG 2>&1
echo "****************************************************************" >> $LOG 2>&1 echo "****************************************************************" >> $LOG 2>&1
sendemail -o tls=no -f "NAS BACKUP <$MAILFROM>" -t $MAILTO -u "$BODSUBJECT" -m "$BODSUBJECT" -a $LOG -s $SMTP >> $LOG 2>&1 sendemail -o tls=no -f "NAS BACKUP <$MAILFROM>" -t $MAILTO -u "$BODSUBJECT" -m "$BODSUBJECT" -a $LOG -s $SMTP >> $LOG 2>&1
find $LOGFOLDER/* -mtime +$N_DAYS -exec rm {} \; find $LOGFOLDER/* -mtime +$N_DAYS -exec rm {} \;