Remote TAR Backups

Remote TAR Backups

Depending on your network configurations and firewalls, you may have an easier time going one way than another, so below are given the commands for these two situations:

  • a remote backup server for a local machine
  • a local backup server for a remote machine

Save a TAR back-up on a remote server

This allows you to have a remote back-up server and want to generate a backup for the current server, saving it directly to the remote server rather than storing it locally and transferring afterwards. If the backup is many gigabytes in size doing it in one steps could save significant time and disk space.

tar -czvf - /source/directory | ssh myuid@remoteserver "dd of=/var/tmp/my-backup.tgz"
tar -cjvf - /another/directory | ssh myuid@10.11.12.5 "dd of=/backup/whatever.tbz2"

Drop the 'v' parameter here and in the rest of the examples if you don't want to see the file list, but probably it is helpful to see the list because otherwise you will have no indication of progress.

Make a local TAR back-up of a remote server

If you want to do the reverse—create a backup on the local server of files on a remote server—then you can pass a command over SSH and have the output captured on the local machine:

ssh myuid@remoteserver 'tar -czvf - /source/directory/ | gzip -9' > /backup/local-backup.tgz

Restore a TAR backup from a remote server

To restore a back-up that is stored on a remote server to the local server:

ssh myuid@remoteserver "cat /var/tmp/my-backup.tgz" | tar -xzvf -

Restore a local TAR backup to a remote server

To restore a local back-up (i.e., stored on the local server) and save the restored data to a remote server:

cat /backup/local-backup.tgz | ssh myuid@remoteserver "tar -C /destination/root/path -xzvf -"