rewritten. only send notification if there were files transfered

This commit is contained in:
Peter Wood
2023-10-25 07:19:22 -04:00
parent cefd7fc0a3
commit 4ed5d253e2

View File

@@ -1,13 +1,45 @@
#!/bin/bash
function move-backups() {
rsync --recursive --quiet -e 'ssh -p 58022' --include '*.gz' --remove-source-files acedanger@vperanda:/home/acedanger/backup/docker-data /mnt/share/media/backups/
}
if [ "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then
move-backups
if [ ! "$(expr substr $(uname -s) 1 5)" == 'Linux' ]; then
exit 1
fi
source="/home/acedanger/backup/docker-data/"
destination="/mnt/share/media/backups/docker-data/"
command="rsync \
--archive --verbose --progress --dry-run --stats \
-e 'ssh -p 58022' \
--include '*.gz' \
acedanger@vperanda:$source $destination \
| fgrep 'Number of files' | cut -d' ' -f4 | tr -d ,"
# echo 'Running command => '
# echo $command
num_files=$(rsync \
--archive --verbose --progress --dry-run --stats \
-e 'ssh -p 58022' \
--include '*.gz' \
acedanger@vperanda:$source $destination \
| fgrep 'Number of files' | cut -d' ' -f4 | tr -d ,
)
# echo 'There are' "${num_files}" 'file(s) to be transferred.'
if [ "$num_files" == 0 ];
then
echo 'There are no files to transfer. Exiting.'
exit 1
fi
# move the files from $source to $destination
rsync \
--recursive --verbose --progress --remove-source-files --archive \
-e 'ssh -p 58022' \
--include '*.gz' \
acedanger@vperanda:$source $destination
# send a notification to https://notify.peterwood.rocks/lab
curl \
-H priority:default \