From e0dd8972fa7d83cafc512f1d9e29841fe5387db3 Mon Sep 17 00:00:00 2001 From: Eugene Fedorych Date: Mon, 14 Aug 2017 08:08:45 +0300 Subject: [PATCH] Second version. Colored --- bkp_to_webdav.sh | 57 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/bkp_to_webdav.sh b/bkp_to_webdav.sh index b43ffc0..27100c3 100755 --- a/bkp_to_webdav.sh +++ b/bkp_to_webdav.sh @@ -1,50 +1,73 @@ #!/bin/sh +# version 2.0 -# DATA +# SETTINGS date=$(date "+%Y%m%d") time=$(date "+%H%M%S") root=~/ -#Target for backup +# Target for backup src=EDU archive_name=$src\_$date\_$time webdav_path=https://webdav.yandex.ua/Backups volume_name=WEBDAV_YANDEX -# End DATA + +delete_local_backup=false +# End SETTINGS # SCRIPT -pushd $root +printf "\e[43;30m ## $src BACKUPPER ## \e[0m\n" +pushd $root &> /dev/null if [ ! -d $volume_name ]; then mkdir $volume_name fi diskutil unmountDisk force $volume_name &> /dev/null -echo "\nLogin to $webdav_path:" +printf "\e[33m## Mounting to $webdav_path...\e[0m\n" +printf "\e[34m\nLogin to $webdav_path:\e[0m\n" if mount_webdav -i -s $webdav_path $volume_name; then - echo "## Mount successful for $volume_name" + printf "\n\e[32m## Mounting successful\e[0m\n" mv $src $archive_name - zip -rXv $archive_name.zip $archive_name + printf "\e[33m## Archiving $src to $archive_name.zip...\e[0m\n" + if zip -rXv $archive_name.zip $archive_name &> /dev/null; then + printf "\e[32m## $src archived\e[0m\n" + else + printf "\e[31m## $src not archived\e[0m\n" + fi mv $archive_name $src total_size=$(du -hs $archive_name.zip) - echo "## Total files size: $total_size" - echo "## Copying files to $volume_name..." - if cp -v $archive_name.zip $volume_name; then - echo "## Сopying to $volume_name successful" + printf "\e[34m## Total files size: $total_size\e[0m\n" + printf "\e[33m## Copying files to $volume_name...\e[0m\n" + if cp -v $archive_name.zip $volume_name &> /dev/null; then + printf "\e[32m## Сopying successful\e[0m\n" else - echo "## Сopying to $volume_name not successful" + printf "\e[31m## Сopying not successful\e[0m\n" fi - rm -rf $archive_name.zip - diskutil unmountDisk force $volume_name + if $delete_local_backup; then + printf "\e[33m## Removing local backup $archive_name.zip...\e[0m\n" + if rm -r $archive_name.zip; then + printf "\e[32m## Local backup removed\e[0m\n" + else + printf "\e[31m## Local backup not removed\e[0m\n" + fi + fi + + printf "\e[33m## Unmounting $volume_name...\e[0m\n" + if diskutil unmountDisk force $volume_name &> /dev/null; then + printf "\e[32m## Unmount successful\e[0m\n" + else + printf "\e[31m## Unmount not successful\e[0m\n" + fi else - echo "## Mount failed for $volume_name" + printf "\n\e[31m## Mounting failed\e[0m\n" fi rm -rf $volume_name -popd -# End SCRIPT \ No newline at end of file +popd &> /dev/null +# End SCRIPT