Quick and dirty remote unix backups

So you need to backup a remote unix system but don’t have enough free disk space to tar locally and then tranfer? Try this!

ssh username@hostname.tld “tar -zcvf – / –exclude /proc –exclude /dev ” | cat > my-system-backup.tgz

This is a breakdown of what this does:

– Starts an ssh session with your remote system (hostname.tld)
– Executes tar -zcvf – / –exclude /proc –exclude /dev ( the exclude statements ensure we don’t grab bits we don’t want, /proc for sure)
– Since tar has – as the filename it pipes the output to the shell, which in turn is piped into cat
– The > redirects the output into a filename of your choice, the .tgz indicated Gzip’d tar file, you can name it whatever you like but .tgz is a standard.

The above command will backup the entire system but you can specify any path, a simple . will backup all your home dir contents on the remote system. I have found this handy on several occasions when I needed a quick and dirty backup of some files on a remote host. Backups to the remote hosts local disk aren’t much good if the system goes down!