Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:52:09+00:00 2026-05-29T10:52:09+00:00

I have a backup script which copies a file via ssh and creates a

  • 0

I have a backup script which copies a file via ssh and creates a hash file during transfer. Additionally pv is used to display a progress bar:

ssh $host "cat '$src_dir/$filename'" \
    | pv --bytes --eta --progress --rate --timer --wait  $opts \
    | tee "$filename" \
    | sha1sum > "$filename.sha1"

To display the progress bar correctly I need to pass the size of the file to pv. At the moment I do that by giving the size of the last backup file.

It is important that everything is done with 1 ssh call because I don’t want to authorize multiple times for 1 backup. SSH keys are in use but secured with a passphrase.

My idea is to call ssh $host "stat -c%s '$src_dir/$filename'; cat '$src_dir/$filename'" and split the output after the 1st line. I could read the filesize and then call pv on the rest of the input.

The backup script is working fine. This is just an exercise for the fun of it. Any ideas are appreciated but I will not completely rewrite the whole script. Especially I won’t switch to scp because I can’t do the hashing during transfer then and I don’t want to trust the local storage for that (of course I do, but then why do we do hashing anyway?).

Update: I ended up doing this:

ssh $host "cd '$src_dir' && stat -c%s '$filename' && sha1sum '$filename' && cat '$filename'" | {
        read size;
        head -n 1 > "$filename.sha1";
        pv --bytes --eta --progress --rate --size $size --timer --wait > "$filename"
    }

It works perfectly and has the advantage that the hash is computed at the remote site. So not only before writing to disk but before doing the network transfer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:52:10+00:00Added an answer on May 29, 2026 at 10:52 am

    In this example, I use stat on OSX, which uses z for the format string for size:

    $ { stat -f %z input; cat input; } | { read s; echo $s; }
    

    Replace the first command list with your ssh call, and replace the echo with you pv list, and you are good to go. In other words, your final command should be:

    $ ssh $host "stat -c%s '$src_dir/$filename'; cat '$src_dir/$filename'" | {
        read size;
        pv --bytes --eta --progress --rate --timer --wait --size $size |
        tee "$filename" |
        sha1sum; } > "$filename.sha1"
    

    I few things to note: I don’t have access to pv and did not check the above.
    I replaced your line continuations with pipe symbols, because I think
    it looks nicer.

    Another idea: on the right hand side of the pipe, you could do:

    { pv --bytes ... --size $( sed 1q ) |
    ...
    

    This definitely relies on sed not reading past the first newline, and I do not know if that is guaranteed by any standard, but it works with … oh my, my sed does not support –version, -?, or -h, and I do not know the package management system of OS X well enough to tell you what sed I’m running. It works with some version of BSD sed…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been asked to generate a Backup Script. Which comprises of a lot
I have used visual studio(vs2010) installer to restore a database backup file to the
I am trying to make a Postgres PHP backup script. I have downloaded one
I have a php script that backup my table in .sql format and I
I have created a shell script to backup my webfiles + database dump, put
i have this script: BACKUP DATABASE timeclockplus TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\backup.bak'
I have a bat script in which gets all files in a folder and
I have a situation in which I have taken a backup(sql scripyts containing the
I have the following script running to backup my apache logs #!/bin/sh dt=`date +%m%d%Y`
I have a TSQL script that is used to set up a database as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.