Skip to content

Commit

Permalink
Updated extension for 0.6.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
framps committed Jan 13, 2019
1 parent 4308951 commit a1233ea
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 57 deletions.
48 changes: 23 additions & 25 deletions extensions/raspiBackup_disk_post.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#######################################################################################################################
#
# Plugin for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called after a backup finished
#
# Function: Display disk usage and % of disk usage change before and after backup
Expand Down Expand Up @@ -31,20 +32,17 @@ ext_diskUsage_post=( $(getDiskUsage) )

# set any messages and prefix message name with ext_ and some unique prefix to use a different namespace than the script
MSG_EXT_DISK_USAGE="ext_diskusage_2"
MSG_EN[$MSG_EXT_DISK_USAGE]="--- RBK1002I: Disk usage pre backup: Used: %s Free: %s"
MSG_DE[$MSG_EXT_DISK_USAGE]="--- RBK1002I: Partitionsauslastung vor dem Backup: Belegt: %s Frei: %s"
MSG_EN[$MSG_EXT_DISK_USAGE]="RBK1002I: Disk usage pre backup: Used: %s Free: %s"
MSG_DE[$MSG_EXT_DISK_USAGE]="RBK1002I: Partitionsauslastung vor dem Backup: Belegt: %s Frei: %s"
MSG_EXT_DISK_USAGE2="ext_diskusage_3"
MSG_EN[$MSG_EXT_DISK_USAGE2]="--- RBK1003I: Disk usage post backup: Used: %s Free: %s"
MSG_DE[$MSG_EXT_DISK_USAGE2]="--- RBK1003I: Partitionsauslastung nach dem Backup: Belegt: %s Frei: %s"
MSG_EN[$MSG_EXT_DISK_USAGE2]="RBK1003I: Disk usage post backup: Used: %s Free: %s"
MSG_DE[$MSG_EXT_DISK_USAGE2]="RBK1003I: Partitionsauslastung nach dem Backup: Belegt: %s Frei: %s"
MSG_EXT_DISK_USAGE3="ext_diskusage_4"
MSG_EN[$MSG_EXT_DISK_USAGE3]="--- RBK1004I: Free change: %s (%s %)"
MSG_DE[$MSG_EXT_DISK_USAGE3]="--- RBK1004I: Änderung freier Platz: %s (%s %)"
MSG_EN[$MSG_EXT_DISK_USAGE3]="RBK1004I: Free change: %s (%s %%)"
MSG_DE[$MSG_EXT_DISK_USAGE3]="RBK1004I: Änderung freier Platz: %s (%s %%)"
MSG_EXT_DISK_USAGE4="ext_diskusage_5"
MSG_EN[$MSG_EXT_DISK_USAGE4]="--- RBK1005E: bc not found. Please install bc first."
MSG_DE[$MSG_EXT_DISK_USAGE4]="--- RBK1004E: bc nicht gefunden. bc muss installiert werden."
MSG_EXT_DISK_USAGE5="ext_diskusage_6"
MSG_EN[$MSG_EXT_DISK_USAGE4]="--- RBK1006E: Error retrieving data."
MSG_DE[$MSG_EXT_DISK_USAGE4]="--- RBK1006E: Fehler beim Datensammeln."
MSG_EN[$MSG_EXT_DISK_USAGE4]="RBK1005E: bc not found. Please install bc first."
MSG_DE[$MSG_EXT_DISK_USAGE4]="RBK1004E: bc nicht gefunden. bc muss installiert werden."

# now write message to console and log and email
# $MSG_LEVEL_MINIMAL will write message all the time
Expand All @@ -54,24 +52,24 @@ if ! which bc &>/dev/null; then
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE4
else

[[ -n ${ext_diskUsage_pre[2]} ]] && usagePre=$( bc <<< "${ext_diskUsage_pre[2]} * 1024" ) || usagePre=0
[[ -n ${ext_diskUsage_post[2]} ]] && usagePost=$( bc <<< "${ext_diskUsage_post[2]} * 1024" ) || usagePost=0
[[ -n ${ext_diskUsage_pre[3]} ]] && freePre=$( bc <<< "${ext_diskUsage_pre[3]} * 1024" ) || freePre=0
[[ -n ${ext_diskUsage_post[3]} ]] && freePost=$( bc <<< "${ext_diskUsage_post[3]} * 1024" ) || freePost=0
[[ -n ${ext_diskUsage_pre[4]} ]] && percentUsedPre=${ext_diskUsage_pre[4]} || percentUsedPre=0
[[ -n ${ext_diskUsage_post[4]} ]] && percentUsedPost=${ext_diskUsage_post[4]} || percentUsedPost=0
# Filesystem 1K-blocks Used Available Use% Mounted on
# /dev/root 15122316 6400128 7930972 45% /

usagePre=$( bc <<< "${ext_diskUsage_pre[2]} * 1024" )
usagePost=$( bc <<< "${ext_diskUsage_post[2]} * 1024" )
freePre=$( bc <<< "${ext_diskUsage_pre[3]} * 1024" )
freePost=$( bc <<< "${ext_diskUsage_post[3]} * 1024" )
percentUsedPre=${ext_diskUsage_pre[4]}
percentUsedPost=${ext_diskUsage_post[4]}

freeChange=$( bc <<< "$freePost - $freePre" )

if (( $freePre == 0 )); then
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE4
else
# Use bytesToHuman from raspiBackup which displays a number in a human readable form
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE "$(bytesToHuman $usagePre)" "$(bytesToHuman $freePre)"
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE2 "$(bytesToHuman $usagePost)" "$(bytesToHuman $freePost)"

if (( $freePre != 0 )); then
freeChangePercent=$( printf "%3.2f" $(bc <<<"( $freePost - $freePre ) * 100 / $freePre") )

# Use bytesToHuman from raspiBackup which displays a number in a human readable form
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE "$(bytesToHuman $usagePre)" "$(bytesToHuman $freePre)"
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE2 "$(bytesToHuman $usagePost)" "$(bytesToHuman $freePost)"
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_USAGE3 "$(bytesToHuman $freeChange)" "$freeChangePercent"
fi
fi
12 changes: 8 additions & 4 deletions extensions/raspiBackup_disk_pre.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash
#######################################################################################################################
#
# Plugin for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called before a backup is started
#
# Function: Display disk usage and % of disk usage change before and after backup
#
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
#
#######################################################################################################################
#
Expand All @@ -26,11 +27,14 @@
#
#######################################################################################################################

# define functions needed
# define functions needed
# use local for all variables used so the script namespace is not poluted

# Filesystem 1K-blocks Used Available Use% Mounted on
# /dev/root 15122316 6400128 7930972 45% /

function getDiskUsage() {
local diskUsage=$(df $BACKUPPATH | grep "/dev")
local diskUsage=$(df $BACKUPPATH | tail -n+2)
echo "$(echo $diskUsage)"
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/raspiBackup_execute_post.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#######################################################################################################################
#
# Plugin for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called after a backup finished
#
# Function: Call another script
Expand Down
26 changes: 21 additions & 5 deletions extensions/raspiBackup_fstab_ready.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
#!/bin/bash

#######################################################################################################################
#
# extensionpoint for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called before dd, tar or rsync backup is started
#
# Function: Copy /etc/fstab into backupdirectory
#
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
#
# (C) 201i7 - framp at linux-tips-and-tricks dot de
#######################################################################################################################
#
# Copyright (C) 2017 framp at linux-tips-and-tricks dot de
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.#
#
#######################################################################################################################

# set any messages and prefix message name with ext_ and some unique prefix to use a different namespace than the script
MSG_EXT_FSTAB_COPY="ext_fstab_copy"
MSG_EN[$MSG_EXT_FSTAB_COPY]="--- RBK1005I: Copy %s to %s"
MSG_DE[$MSG_EXT_FSTAB_COPY]="--- RBK1005I: Kopiere %s in %s"
MSG_EN[$MSG_EXT_FSTAB_COPY]="RBK1005I: Copy %s to %s"
MSG_DE[$MSG_EXT_FSTAB_COPY]="RBK1005I: Kopiere %s in %s"

FSTAB_FILENAME="/etc/fstab"
FSTAB_TARGET_DIR="raspiBackup/extensionSaveArea"
Expand Down
5 changes: 3 additions & 2 deletions extensions/raspiBackup_mail.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
#######################################################################################################################
#
# Sample implementation for email plugin for raspiBackup.sh
# Sample email plugin for raspiBackup.sh
#
# Function: Send success/failure email
#
# Enable with 'mailext' as parameter to -s
#
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
#
#######################################################################################################################
#
Expand Down
10 changes: 4 additions & 6 deletions extensions/raspiBackup_mem_post.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#######################################################################################################################
#
# Plugin for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called after a backup finished
#
# Function: Display memory free and used in MB
Expand Down Expand Up @@ -31,13 +32,10 @@ ext_freememory_post=( $(getMemoryFree) )

# set any messages and prefix message name with ext_ and some unique prefix to use a different namespace than the script
MSG_EXT_DISK_FREE="ext_freememory_1"
MSG_EN[$MSG_EXT_DISK_FREE]="--- RBK1001I: Memory usage - Pre backup - Used: %s MB Free: %s MB - Post backup - Used: %s MB Free: %s MB"
MSG_DE[$MSG_EXT_DISK_FREE]="--- RBK1001I: Speicherauslastung - Vor dem Backup - Belegt: %s MB Frei: %s MB - Nach dem Backup: Belegt: %s MB Frei: %s MB"
MSG_EN[$MSG_EXT_DISK_FREE]="RBK1001I: Memory usage - Pre backup - Used: %s MB Free: %s MB - Post backup - Used: %s MB Free: %s MB"
MSG_DE[$MSG_EXT_DISK_FREE]="RBK1001I: Speicherauslastung - Vor dem Backup - Belegt: %s MB Frei: %s MB - Nach dem Backup: Belegt: %s MB Frei: %s MB"

# now write message to console and log and email
# $MSG_LEVEL_MINIMAL will write message all the time
# $MSG_LEVEL_DETAILED will write message only if -m 1 parameter was used
writeToConsole $MSG_LEVEL_MINIMAL $MSG_EXT_DISK_FREE "${ext_freememory_pre[0]}" "${ext_freememory_pre[1]}" "${ext_freememory_post[0]}" "${ext_freememory_post[1]}"



13 changes: 9 additions & 4 deletions extensions/raspiBackup_mem_pre.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#######################################################################################################################
#
# Plugin for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called before a backup is started
#
# Function: Display memory free and used in MB
Expand Down Expand Up @@ -29,11 +30,15 @@
# define functions needed
# use local for all variables used so the script namespace is not poluted

# total used free shared buff/cache available
#Mem: 481 55 34 8 391 353
#Swap: 99 83 16

function getMemoryFree() {
local temp=$(free -m | grep "^-" | cut -d ':' -f 2)
echo "$(echo $temp)"
eval set -- "$(free -m |grep -i 'Mem:')"
echo "$3 $4"
}

# set any variables and prefix all names with ext_ and some unique prefix to use a different namespace than the script
ext_freememory_pre=( $(getMemoryFree) )
# set any variables and prefix all names with ext_ and some unique prefix to use a different namespace than the script

7 changes: 4 additions & 3 deletions extensions/raspiBackup_temp_post.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#######################################################################################################################
#
# Plugin for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called after a backup finished
#
# Function: Display CPU temperature
Expand Down Expand Up @@ -31,8 +32,8 @@ ext_CPUTemp_post=$(getCPUTemp)

# set any messages and prefix message name with ext_ and some unique prefix to use a different namespace than the script
MSG_EXT_CPU_TEMPERATURE="ext_CPUTemp_1"
MSG_EN[$MSG_EXT_CPU_TEMPERATURE]="--- RBK1000I: CPU temperature pre and post backup: %s - %s"
MSG_DE[$MSG_EXT_CPU_TEMPERATURE]="--- RBK1000I: CPU Temperatur vor und nach dem Backup: %s - %s"
MSG_EN[$MSG_EXT_CPU_TEMPERATURE]="RBK1000I: CPU temperature pre and post backup: %s - %s"
MSG_DE[$MSG_EXT_CPU_TEMPERATURE]="RBK1000I: CPU Temperatur vor und nach dem Backup: %s - %s"

# now write message to console and log and email
# $MSG_LEVEL_MINIMAL will write message all the time
Expand Down
28 changes: 22 additions & 6 deletions extensions/raspiBackup_temp_pre.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
#!/bin/bash

########################################################################################################################
#
# extensionpoint for raspiBackup.sh
# Sample plugin for raspiBackup.sh
# called before a backup is started
#
#
# Function: Display CPU temperature
#
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
#
#######################################################################################################################
#
# Copyright (C) 2015 framp at linux-tips-and-tricks dot de
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# (C) 2015 - framp at linux-tips-and-tricks dot de
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.#
#
#######################################################################################################################

# define functions needed
# define functions needed
# use local for all variables so the script namespace is not polluted

function getCPUTemp() {
Expand Down
40 changes: 40 additions & 0 deletions extensions/testExtensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
########################################################################################################################
#
# Function: Invoke all sample plugins. Helps to debug and develop plugins
#
# See http://www.linux-tips-and-tricks.de/raspiBackup for additional information
#
########################################################################################################################
#
# Copyright (C) 2018 framp at linux-tips-and-tricks dot de
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.#
#
#######################################################################################################################

if [[ -f ../raspiBackup.sh ]]; then
. ../raspiBackup.sh --include
else
. raspiBackup.sh --include
fi

. raspiBackup_disk_pre.sh
. raspiBackup_disk_post.sh

. raspiBackup_mem_pre.sh
. raspiBackup_mem_post.sh

. raspiBackup_temp_pre.sh
. raspiBackup_temp_post.sh

0 comments on commit a1233ea

Please sign in to comment.