How to tar a file via ssh when space is over

It may happen that the filesystem gets bloated by a growing log file when some process gets mad
and starts writing to logs in a blind fury. Or maybe you forgot to add that server to nagios for monitoring of free space.

Whatever the reason, you may need to delete a big file, but you don't want to just delete it. Maybe you want to
free system space to allow services to restart (ASAP) but want to keep the big file for analysis.

With tar you can stream over ssh and have the tar saved on the other end.

Command looks something like this:

tar cz - offending-big-file.log | ssh you@other-server " cat > offending-big-file.log.gz"

Remember to restart or kill any process holding a reference to the deleted file, otherwise the system won't free space on disk.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s