Automation Techs For Productivity And Fun

An Easy Way To Compress And Download Log Files From Remote Server Using Node.js

As I've written in the article below, there is a quite easy way to connect to and control remote Linux servers with Node.js.

How To Manage Remote Servers And Databases Through SSH Tunnel With Node.js

I've shown examples to run commands on server, and executing queries on remote database using the "node-ssh" package. These kind of remote scripts makes it easy to save time managing massive servers.

This time, I want to show you how to automate file downloading from remote servers.

Collecting and analyzing log files are common tasks for server admins. Log files are often huge, so you have to compress the file, download it to local machine, decompress the file at local, and delete the compressed file from server. It's not a difficult task, but it takes time. And this task comes up repeatedly.

There are nice packages for Node.js to automate these tasks.

"node-ssh" is a package for SSH connecting, and it also have functions to upload and download files through SSH.

"tar" package have functions to compress and decompress files, and it works also on Windows.

Using these packages, I've wrote a script that...

  1. Connect with SSH to remote server
  2. Compress log file with tar command
  3. Download compressed log file to local machine
  4. Delete compressed file from server
  5. Decompress log file on local machine
Here is the script:


Search This Blog


Generate Data For Testing With PostgreSQL

When developing a software using PostgreSQL database as storage, the function "generated_series" is very useful to create data ...

Powered by Blogger.


Recent Posts