Tailscale C++ File Backup System
A lightweight, dependency-free C++ application designed to securely transfer and back up files directly between local machines over a Tailscale network.
Overview
This project is a custom, lightweight file backup system built entirely in C++ that leverages a Tailscale network for secure, direct machine-to-machine transfers. I wanted a reliable way to back up files between my local machines without relying on third-party cloud providers or dealing with complex network configurations. By utilizing standard POSIX sockets over Tailscale's private 100.x.x.x IP space, the application treats remote machines as if they are sitting on the exact same local network, ensuring fast, private, and secure backups.
Key Features
- Direct Transfer: Peer-to-peer file transfer over a secure Tailscale mesh overlay.
- Custom TCP Protocol: Reliable data transmission using a strict header-and-payload system to ensure no packets are dropped.
- Dependency-Free Core: Built using raw POSIX sockets and standard C++ libraries, keeping the application's footprint incredibly minimal.
- Chunked File I/O: Efficiently reads and transmits large files in manageable binary buffers rather than loading everything into memory at once.
Technology Stack
- C++: Core programming language and file handling (std::ifstream/std::ofstream)
- POSIX Sockets: Low-level TCP network communication layer
- Tailscale: Secure mesh VPN for seamless local networking
Architecture & Implementation
The system is built on a straightforward Client-Server architecture designed to operate seamlessly across a Tailscale network. This approach completely bypassed a major networking challenge: because both machines are connected via Tailscale, I didn't have to deal with complex NAT traversal or router port forwarding. I could simply bind to standard ports and communicate directly.
The architecture is split into two main components: the Receiver and the Sender.
The Receiver acts as the server and runs continuously on the backup destination machine. It creates a POSIX socket, binds to a specific local port, and listens for incoming connections. Once a connection is accepted, it waits for a protocol header containing the incoming file's name and total size.
The Sender acts as the client on the source machine. When a backup is initiated, it opens a socket and connects directly to the Receiver's Tailscale IP address. It determines the target file's size, sends the necessary header metadata, and then begins reading the local file in optimized binary chunks (e.g., 4KB or 8KB). It streams these chunks over the network until the transfer is complete, while the Receiver simultaneously catches the stream and writes it to the designated backup directory.