diff --git a/move-backups.sh b/move-backups.sh index 5aff03e..cd7dd8f 100755 --- a/move-backups.sh +++ b/move-backups.sh @@ -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 \