Skip to main content

stdin to sftp pump

Project description

stdin2sftp

A very simple pump from stdin to a remote file via sftp. Useful for when one cannot just pipe over ssh to cat or dd, for example. when remote sftp provider is limited to sftp-only, like OpenSSH with ChrootDirectory and internal-sftp, an rclone serve sftp or proftpd with mod_sftp,

Why?

I had a need to make a efficient backups of virtual machines disk images, which means copy-on-write snapshot of disk image, then transfer over the network while applying compression, without the need to first locally save compressed disk image and without blocking the host system or guest virtual machine during the process. The solution for that is to use reflinks as a copy-on-write snapshots, and then stream the content of reflinked disk image while compressing in between, to remote server. Sadly, neither scp nor sftp support reading from pipe., dropping not a file' error. This way the source image is not blocked and is immutable during the backup process regardless how how long all of the compression and transfer take, at no point in tiem I have a whole copy of the disk image and there’s no need to write whole image compressed to disk before transfer.

Real life usage

Make zero-copy snapshot of the Virtual Machine disk image:

cp -a --reflink=always vm_1.qcow2 vm_1.qcow2_snapshot

And upload it over the network, while adding compression to remote file:

zstd -6 < vm_1.qcow2_snapshot | \
stdin2sftp \
  -u backupuser \
  -H backuphost.example.com \
  -f "/mnt/backups/vm_dumps/vm_1/$(date '+%Y-%m-%d_%H-%M-%S').qcow2.zstd"

And if one is worried about saturating network link, an bandwidth limit can be applied with pv. Since with reflink, the source disk image is not blocked regardless of how long the transfer takes:

zstd -6 < vm_1.qcow2_snapshot | \
pv -L 64M | \
stdin2sftp \
  -u backupuser \
  -H backuphost.example.com \
  -f "/mnt/backups/vm_dumps/vm_1/$(date '+%Y-%m-%d_%H-%M-%S').qcow2.zstd"

after which the snapshot can be discarded:

rm -f vm_1.qcow2_snapshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stdin2sftp-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file stdin2sftp-0.1.0.tar.gz.

File metadata

  • Download URL: stdin2sftp-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for stdin2sftp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d284c0947b9eb635235f5f967c3e34ace7f7a08ed8e229620de4b86bf03818ac
MD5 8212d04feacdf5c45c3fb7e290571266
BLAKE2b-256 f1c36093f85ab83140e342e42b222011053555c295b86ed55f0bb3938addebf7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page