Tar a folder or entire system through ssh

We all had the problem of needing to backup a folder or an entire system from a machine before decommissioning or as a postfix backup solution only to find tarring aint gonna work cause you have very little space left. Also there are folders you want to avoid tarring since they contain logs or system virtual folders that you want to skip.

So you need to get a tar from a machine have very little space left and you need to pull all the files in a compressed fashion; the following command calls a backup as root through ssh using tar on the source machine and skips the folders you do not want :

ssh root@pollux "tar zcvf - --exclude=/proc/* --exclude=/dev/* --exclude=/sys/* --exclude=/var/logs/* /" > /root/backup/pollux.fullandfinal.$(date '+%Y-%m-%d-%k-%M').tar.gz

The result of the above command is a backup of the / compressed at source piped through console through ssh back to your local / backup repo machine in .tar.gz format leaving out the rubbish thanks to the :

- --exclude=/proc/* --exclude=/dev/* --exclude=/sys/* --exclude=/var/logs/*

section. Note the “– —” the first – indicates extended parameters and –except leaves out any match to the path.

There you go one command to back them all.

(this could be easily bash-ed and cron-ed to produce a decent makeshift backup tool.

To check out the contents of the tar file you can use

tar -tvzf <archive.tar.gz>

This will show you the contents and leave a fail exit code in a bash script.

 

Write a Reply or Comment

Your email address will not be published.