Ubuntu 16.04 tar backup with progress bar PV (Pipe Viewer) not working












0















I'm trying to create a Bash script that does backup of my important files in home folder once, every week. I haven't gotten to the crontab part yet but I've been trying to make this progress bar work. I want to know how long I have to wait for till it's done. I don't want to just put echo "Process ongoing, please wait". Please help



Bash code:



TODAY=$(date +%d-%m-%Y)
echo $TODAY
file="Exist_or_Not.txt"
type pv > $file
if grep -q "pv" $file; then
echo "exists"
else
echo "Installing pv for progress bar"
sudo apt install pv
fi
#SIZE='du -sk /home/user/{Desktop,Documents,Downloads} | cut -f 1'
sudo tar -pczf /media/backups/backup${TODAY}.tar.gz /home/user/Desktop /home/user/Documents /home/user/Downloads | pv -s 40978228k > /dev/null


I got that 40978228k by calculating what I got from $SIZE in Python. Summed these numbers up, num1 + num 2 + num3 because ${SIZE}k didn't work. It kept saying pv: -s: integer argument expected










share|improve this question



























    0















    I'm trying to create a Bash script that does backup of my important files in home folder once, every week. I haven't gotten to the crontab part yet but I've been trying to make this progress bar work. I want to know how long I have to wait for till it's done. I don't want to just put echo "Process ongoing, please wait". Please help



    Bash code:



    TODAY=$(date +%d-%m-%Y)
    echo $TODAY
    file="Exist_or_Not.txt"
    type pv > $file
    if grep -q "pv" $file; then
    echo "exists"
    else
    echo "Installing pv for progress bar"
    sudo apt install pv
    fi
    #SIZE='du -sk /home/user/{Desktop,Documents,Downloads} | cut -f 1'
    sudo tar -pczf /media/backups/backup${TODAY}.tar.gz /home/user/Desktop /home/user/Documents /home/user/Downloads | pv -s 40978228k > /dev/null


    I got that 40978228k by calculating what I got from $SIZE in Python. Summed these numbers up, num1 + num 2 + num3 because ${SIZE}k didn't work. It kept saying pv: -s: integer argument expected










    share|improve this question

























      0












      0








      0








      I'm trying to create a Bash script that does backup of my important files in home folder once, every week. I haven't gotten to the crontab part yet but I've been trying to make this progress bar work. I want to know how long I have to wait for till it's done. I don't want to just put echo "Process ongoing, please wait". Please help



      Bash code:



      TODAY=$(date +%d-%m-%Y)
      echo $TODAY
      file="Exist_or_Not.txt"
      type pv > $file
      if grep -q "pv" $file; then
      echo "exists"
      else
      echo "Installing pv for progress bar"
      sudo apt install pv
      fi
      #SIZE='du -sk /home/user/{Desktop,Documents,Downloads} | cut -f 1'
      sudo tar -pczf /media/backups/backup${TODAY}.tar.gz /home/user/Desktop /home/user/Documents /home/user/Downloads | pv -s 40978228k > /dev/null


      I got that 40978228k by calculating what I got from $SIZE in Python. Summed these numbers up, num1 + num 2 + num3 because ${SIZE}k didn't work. It kept saying pv: -s: integer argument expected










      share|improve this question














      I'm trying to create a Bash script that does backup of my important files in home folder once, every week. I haven't gotten to the crontab part yet but I've been trying to make this progress bar work. I want to know how long I have to wait for till it's done. I don't want to just put echo "Process ongoing, please wait". Please help



      Bash code:



      TODAY=$(date +%d-%m-%Y)
      echo $TODAY
      file="Exist_or_Not.txt"
      type pv > $file
      if grep -q "pv" $file; then
      echo "exists"
      else
      echo "Installing pv for progress bar"
      sudo apt install pv
      fi
      #SIZE='du -sk /home/user/{Desktop,Documents,Downloads} | cut -f 1'
      sudo tar -pczf /media/backups/backup${TODAY}.tar.gz /home/user/Desktop /home/user/Documents /home/user/Downloads | pv -s 40978228k > /dev/null


      I got that 40978228k by calculating what I got from $SIZE in Python. Summed these numbers up, num1 + num 2 + num3 because ${SIZE}k didn't work. It kept saying pv: -s: integer argument expected







      command-line bash scripts backup






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 19 at 12:19









      Kristen UngurKristen Ungur

      334




      334






















          1 Answer
          1






          active

          oldest

          votes


















          1














          EDIT: Full code, working!



          #!/bin/bash

          TODAY=$(date +%d-%m-%Y)
          f="tekst.txt"
          type pv > $f
          if grep -q "pv" $f; then
          echo "PV exists"
          else
          echo "Installing PV..."
          sudo apt install pv
          fi
          f2="home_backup${TODAY}.tar.gz"
          echo "Your username is: $(whoami)"
          echo "1) Backup your home directory"
          echo "2) Extract your backup"
          read -p "Choose the option: " choice
          if [ -z $choice ]; then
          echo "Choose the option"
          continue
          elif [ $choice -eq 1 ]; then
          echo "Backup directory: /media/backup/"
          sleep 1
          echo "Backup Process Activated"
          sudo tar -cf - /home/$(whoami) -P | pv -s $(du -sb /home/$(whoami) | awk '{print $1}') | gzip > /media/extracted/$f2
          elif [ $choice -eq 2 ]; then
          echo "Extracting your backupped home directory from /media/backup/"
          echo "Extracted directories go to /media/extracted/"
          sleep 1
          echo "Extraction Process Activated"
          pv /media/extracted/$f2 | sudo tar -xzf - -C /media/extracted/
          fi





          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1119508%2fubuntu-16-04-tar-backup-with-progress-bar-pv-pipe-viewer-not-working%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            EDIT: Full code, working!



            #!/bin/bash

            TODAY=$(date +%d-%m-%Y)
            f="tekst.txt"
            type pv > $f
            if grep -q "pv" $f; then
            echo "PV exists"
            else
            echo "Installing PV..."
            sudo apt install pv
            fi
            f2="home_backup${TODAY}.tar.gz"
            echo "Your username is: $(whoami)"
            echo "1) Backup your home directory"
            echo "2) Extract your backup"
            read -p "Choose the option: " choice
            if [ -z $choice ]; then
            echo "Choose the option"
            continue
            elif [ $choice -eq 1 ]; then
            echo "Backup directory: /media/backup/"
            sleep 1
            echo "Backup Process Activated"
            sudo tar -cf - /home/$(whoami) -P | pv -s $(du -sb /home/$(whoami) | awk '{print $1}') | gzip > /media/extracted/$f2
            elif [ $choice -eq 2 ]; then
            echo "Extracting your backupped home directory from /media/backup/"
            echo "Extracted directories go to /media/extracted/"
            sleep 1
            echo "Extraction Process Activated"
            pv /media/extracted/$f2 | sudo tar -xzf - -C /media/extracted/
            fi





            share|improve this answer






























              1














              EDIT: Full code, working!



              #!/bin/bash

              TODAY=$(date +%d-%m-%Y)
              f="tekst.txt"
              type pv > $f
              if grep -q "pv" $f; then
              echo "PV exists"
              else
              echo "Installing PV..."
              sudo apt install pv
              fi
              f2="home_backup${TODAY}.tar.gz"
              echo "Your username is: $(whoami)"
              echo "1) Backup your home directory"
              echo "2) Extract your backup"
              read -p "Choose the option: " choice
              if [ -z $choice ]; then
              echo "Choose the option"
              continue
              elif [ $choice -eq 1 ]; then
              echo "Backup directory: /media/backup/"
              sleep 1
              echo "Backup Process Activated"
              sudo tar -cf - /home/$(whoami) -P | pv -s $(du -sb /home/$(whoami) | awk '{print $1}') | gzip > /media/extracted/$f2
              elif [ $choice -eq 2 ]; then
              echo "Extracting your backupped home directory from /media/backup/"
              echo "Extracted directories go to /media/extracted/"
              sleep 1
              echo "Extraction Process Activated"
              pv /media/extracted/$f2 | sudo tar -xzf - -C /media/extracted/
              fi





              share|improve this answer




























                1












                1








                1







                EDIT: Full code, working!



                #!/bin/bash

                TODAY=$(date +%d-%m-%Y)
                f="tekst.txt"
                type pv > $f
                if grep -q "pv" $f; then
                echo "PV exists"
                else
                echo "Installing PV..."
                sudo apt install pv
                fi
                f2="home_backup${TODAY}.tar.gz"
                echo "Your username is: $(whoami)"
                echo "1) Backup your home directory"
                echo "2) Extract your backup"
                read -p "Choose the option: " choice
                if [ -z $choice ]; then
                echo "Choose the option"
                continue
                elif [ $choice -eq 1 ]; then
                echo "Backup directory: /media/backup/"
                sleep 1
                echo "Backup Process Activated"
                sudo tar -cf - /home/$(whoami) -P | pv -s $(du -sb /home/$(whoami) | awk '{print $1}') | gzip > /media/extracted/$f2
                elif [ $choice -eq 2 ]; then
                echo "Extracting your backupped home directory from /media/backup/"
                echo "Extracted directories go to /media/extracted/"
                sleep 1
                echo "Extraction Process Activated"
                pv /media/extracted/$f2 | sudo tar -xzf - -C /media/extracted/
                fi





                share|improve this answer















                EDIT: Full code, working!



                #!/bin/bash

                TODAY=$(date +%d-%m-%Y)
                f="tekst.txt"
                type pv > $f
                if grep -q "pv" $f; then
                echo "PV exists"
                else
                echo "Installing PV..."
                sudo apt install pv
                fi
                f2="home_backup${TODAY}.tar.gz"
                echo "Your username is: $(whoami)"
                echo "1) Backup your home directory"
                echo "2) Extract your backup"
                read -p "Choose the option: " choice
                if [ -z $choice ]; then
                echo "Choose the option"
                continue
                elif [ $choice -eq 1 ]; then
                echo "Backup directory: /media/backup/"
                sleep 1
                echo "Backup Process Activated"
                sudo tar -cf - /home/$(whoami) -P | pv -s $(du -sb /home/$(whoami) | awk '{print $1}') | gzip > /media/extracted/$f2
                elif [ $choice -eq 2 ]; then
                echo "Extracting your backupped home directory from /media/backup/"
                echo "Extracted directories go to /media/extracted/"
                sleep 1
                echo "Extraction Process Activated"
                pv /media/extracted/$f2 | sudo tar -xzf - -C /media/extracted/
                fi






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 19 at 16:20

























                answered Feb 19 at 12:25









                Kristen UngurKristen Ungur

                334




                334






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1119508%2fubuntu-16-04-tar-backup-with-progress-bar-pv-pipe-viewer-not-working%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                    is 'sed' thread safe

                    How to make a Squid Proxy server?