DEV Community

Cover image for Copy Files Compressed with Tar via ssh from and to a Linux Server
Konstantin Filtschew
Konstantin Filtschew

Posted on

Copy Files Compressed with Tar via ssh from and to a Linux Server

Copying files from a development machine or a server to another one may take up a lot of time, resources and traffic which dependent on the task may be more or less a problem. There are common Linux/Unix tools like scp and rsync to do the job, but they may be a wrong choice dependent on the task like:

  • copy a lot of small files (like node_modules) are big like text files or images in uncompressed formats like BMP or TIFF
  • have special attributes set, which you want to transport over the wire (like permissions or user/group IDs set)
  • files with encoding in names, which should be just transferred with errors

The most common Solution in both Directions

These are the most common combination to copy files using tar to compress and ssh for transport (using pipes) which may be suitable for most solutions.

Copy the folder data/ from current machine (development machine or current server) to remote server or system to folder /opt. The sever must support ssh and have tar installed, which is common for most Linux/Unix systems.

tar czf - data/ | ssh user@remoteserver "cd /opt && tar -xvzf - "
Enter fullscreen mode Exit fullscreen mode

Copy the folder data/ in /opt to current machine (development machine or current server) from remote server or system. The server must support ssh and have tar installed, which is common for most Linux/Unix systems.

ssh user@remoteserver "cd /opt && tar -cfz data/" | tar xfzv
Enter fullscreen mode Exit fullscreen mode

Deeper understanding

If you want to get a deeper understanding what all the parameters do, where to use them and which one you may need for which task, check the full article on my site: qameta.com.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay