| date | 2026-03-14 |
|---|---|
| modified | Saturday 14 March 2026 |
| title | Backing up data from VPS to Home server with compression |
I needed to back up all files in /root on my VPS before shutting it down, saving them as a compressed archive on my home server. The catch: my home server is on a local network and not directly reachable from the internet, so the VPS can’t SSH into it directly.
The solution is to stream the archive over SSH with maximum gzip compression, routing through a reverse tunnel opened from my laptop.
vps and home configured in ~/.ssh/config/root/home/emad/vpsSince the VPS can’t reach the home server directly, the laptop opens a reverse SSH tunnel so that a port on the VPS forwards to the home server through the laptop.
In one terminal, run from your laptop:
1ssh -R 2222:home:22 vps
This makes port 2222 on the VPS transparently forward to port 22 on the home server via your laptop. Keep this terminal open for the duration of the backup.
In a second terminal, run from your laptop:
1ssh -A vps \
2 "tar -cf - -C / root | gzip -9 | ssh -o StrictHostKeyChecking=no -p 2222 emad@localhost \
3 'mkdir -p /home/emad/vps && cat > /home/emad/vps/vps-backup-\$(date +%Y%m%d).tar.gz'"
A few things worth noting:
-A forwards your SSH agent to the VPS so it can authenticate to the tunnel without a separate keytar -cf - -C / root streams the /root directory to stdout — no temp file needed on the VPSgzip -9 applies maximum compression before the data goes over the wirelocalhost:2222, which your laptop forwards to the home serveremad@localhost is explicit because the VPS doesn’t have your laptop’s SSH config and doesn’t know the username for the home servervps-backup-YYYYMMDD.tar.gz using the current dateOnce the command finishes, SSH into your home server and check:
1ls -lh /home/emad/vps/
You should see the archive with a reasonable size. To test the integrity of the archive:
1tar -tzf /home/emad/vps/vps-backup-*.tar.gz | head