Merge branch 'development'
Fix notifications
This commit is contained in:
commit
87f3bca955
@ -19,7 +19,7 @@
|
||||
|
||||
#Help function
|
||||
function help_function {
|
||||
echo "simple_backup, version 1.2.3"
|
||||
echo "simple_backup, version 1.3"
|
||||
echo ""
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
@ -54,9 +54,8 @@ function read_conf {
|
||||
if [[ ! -f "$CONFIG" ]]; then
|
||||
#If default config file doesn't exist, exit
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: Configuration file not found" | tee $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
@ -71,10 +70,8 @@ function read_conf {
|
||||
if [[ ! -f "$CONFIG" ]]; then
|
||||
#If the provided configuration file doesn't exist, exit
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: Configuration file not found" | tee -a $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
mv $WARN "$HOMEDIR/.simple_backup/warnings.log"
|
||||
@ -107,9 +104,8 @@ function read_conf {
|
||||
if [[ -z "$BACKUP_DEV" || ! -d "$BACKUP_DEV" ]]; then
|
||||
#If the backup directory is not set or doesn't exist, exit
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: Output folder \"$BACKUP_DEV\" not found" | tee -a $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
@ -173,9 +169,8 @@ function parse_options {
|
||||
|
||||
if [[ -z "$input" ]]; then
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: bad options format" | tee -a $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
@ -205,9 +200,8 @@ function parse_options {
|
||||
|
||||
if [[ -z "$BACKUP_DEV" || ! -d "$BACKUP_DEV" ]]; then
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: output folder \"$BACKUP_DEV\" not found" | tee -a $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
@ -263,9 +257,8 @@ function parse_options {
|
||||
|
||||
if [[ ! -d "/home/$2" ]]; then
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: user $2 doesn't exist" | tee -a $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "HOMEDIR/.simple_bakup/errors.log"
|
||||
@ -295,9 +288,8 @@ function parse_options {
|
||||
|
||||
*)
|
||||
echo "$(date): Backup failed (see errors.log)" >> $LOG
|
||||
echo "Backup failed"
|
||||
echo "Error: Option $1 not recognised. Use 'simple-backup -h' to see available options" | tee -a $ERR
|
||||
#If libnotify is installed, show desktop notification that backup failed
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup failed"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
@ -339,9 +331,8 @@ fi
|
||||
|
||||
if [[ -z $n_in || $n_in -eq 0 ]]; then
|
||||
echo "$(date): Backup finished (no files copied)" >> $LOG
|
||||
echo "Backup finished"
|
||||
echo "Warning: no valid input selected. Nothing to do" | tee -a $WARN
|
||||
#If libnotify is installed, show desktop notification that backup finished
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup finished (warnings)"
|
||||
|
||||
mv $LOG "$HOMEDIR/.simple_backup/simple_backup.log"
|
||||
mv $ERR "$HOMEDIR/.simple_backup/errors.log"
|
||||
@ -351,8 +342,7 @@ if [[ -z $n_in || $n_in -eq 0 ]]; then
|
||||
fi
|
||||
|
||||
echo "$(date): Starting backup" > $LOG
|
||||
#If libnotify is installed, show desktop notification that backup is starting
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Starting backup"
|
||||
echo "Starting backup..."
|
||||
|
||||
#If specified, keep the last n backups and remove the others. Default: keep all
|
||||
if [[ -n $KEEP ]]; then
|
||||
@ -360,7 +350,8 @@ if [[ -n $KEEP ]]; then
|
||||
N_BACKUP=$(($N_BACKUP-1))
|
||||
|
||||
if [[ $N_BACKUP -gt $KEEP ]]; then
|
||||
echo "$(date): Removing old backups..." >> $LOG
|
||||
echo "$(date): Removing old backups" >> $LOG
|
||||
echo "Removing old backups..."
|
||||
REMOVE=$(mktemp)
|
||||
find $BACKUP_DEV/simple_backup/* -maxdepth 0 -type d | sort | head -n $(($N_BACKUP - $KEEP)) >> $REMOVE
|
||||
|
||||
@ -370,6 +361,8 @@ if [[ -n $KEEP ]]; then
|
||||
echo "Removed backup: $line" >> $LOG
|
||||
done<$REMOVE
|
||||
|
||||
echo "Removed old backups"
|
||||
|
||||
rm $REMOVE
|
||||
fi
|
||||
|
||||
@ -389,13 +382,13 @@ fi
|
||||
#Update the logs
|
||||
if [[ $(cat $ERR | wc -l) -gt 0 ]]; then
|
||||
echo "$(date): Backup finished with errors" >> $LOG
|
||||
error_flag=1
|
||||
echo "Backup finished with errors"
|
||||
elif [[ $(cat $WARN | wc -l) -gt 0 ]]; then
|
||||
echo "$(date): Backup finished with warnings" >> $LOG
|
||||
error_flag=2
|
||||
echo "Backup finished (warnings)"
|
||||
else
|
||||
echo "$(date): Backup finished" >> $LOG
|
||||
error_flag=0
|
||||
echo "Backup finished"
|
||||
fi
|
||||
|
||||
#Fix ownership and permissions of log files if needed
|
||||
@ -425,12 +418,4 @@ fi
|
||||
BACKUP_DIR_FULL=$(readlink -f "$BACKUP_DIR")
|
||||
ln -sf "$BACKUP_DIR_FULL" "$BACKUP_DEV/simple_backup/last_backup"
|
||||
|
||||
if [[ $error_flag -eq 0 ]]; then
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup finished"
|
||||
elif [[ $error_flag -eq 1 ]]; then
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup finished (errors)"
|
||||
else
|
||||
! command -v notify-send > /dev/null 2>&1 || DISPLAY=:0.0 notify-send -u low -t 10000 "Backup finished (warnings)"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user