Sub topic 5
Sending backups off the server
Prerequisites
This chapter assumes that you can use the Linux command line, connect with SSH keys, read basic file permissions, and run systemd services. You also need a backup server or object-storage account. The examples use backup.example.com and placeholder credentials. Replace them with values for your environment.
A backup stored only on the server it protects is not enough. Disk failure, theft, ransomware, or an administrator mistake can destroy both the live data and its backup. Send the repository to a separate system or storage service.
Choosing a remote backend
A backend is the storage method that a backup program uses to reach its repository.
| Backend | Best fit | Important requirement |
|---|---|---|
| SSH or SFTP | A second Linux server that you control | Network access and an SSH key |
| S3-compatible object storage | Cloud storage or an internal object store | Bucket credentials and lifecycle planning |
| Local mounted storage | A disk or network mount already managed by Linux | Reliable mounting and access controls |
restic supports SFTP and many S3-compatible services directly. Borg primarily uses a local path or an SSH connection to a remote system running Borg. Borg does not natively write to an S3 bucket as an ordinary repository. An object-storage mount or a gateway can add that capability, but it adds another failure point and should be tested carefully.
SSH and SFTP repositories
Create a dedicated account on the backup host. Give it ownership of a repository directory, but do not give it administrative privileges. Restrict its SSH key to the expected source server when your SSH configuration allows that.
With restic, an SFTP repository is addressed through SSH:
export RESTIC_REPOSITORY='sftp:[email protected]:/srv/restic/myserver'
export RESTIC_PASSWORD_FILE='/etc/restic/password'
restic init
restic backup /etc /home /var/wwwThe first command tells restic to use the backup account and the directory on the remote host. The password file contains the repository encryption password, not the SSH private-key password.
Borg uses SSH to start Borg on the remote host:
export BORG_REPO='ssh://[email protected]/./borg/myserver'
export BORG_PASSCOMMAND='cat /etc/borg/passphrase'
borg init --encryption=repokey-blake2
borg create --stats --compression zstd \
'::{hostname}-{now:%Y-%m-%dT%H:%M:%S}' /etc /home /var/wwwThe ./ in this Borg URL means that borg/myserver is relative to the backup account's home directory. The remote host must have a compatible Borg installation.
Verify the remote host key before the first automated run. Otherwise, a changed key can either stop backups unexpectedly or indicate a serious interception attempt.
Object storage with restic
Object storage stores data as objects inside a bucket. It is usually reachable over HTTPS and can provide durability across hardware failures.
export RESTIC_REPOSITORY='s3:https://objects.example.com/server-backups/myserver'
export AWS_ACCESS_KEY_ID='backup-writer'
export AWS_SECRET_ACCESS_KEY='replace-with-a-secret'
export RESTIC_PASSWORD_FILE='/etc/restic/password'
restic init
restic backup /etc /home /var/wwwUse a credential that can access only this bucket or prefix. Prefer the provider's instance role, workload identity, or secret manager over putting long-lived credentials directly in a script. Configure bucket versioning or object-lock features only after understanding their storage costs and deletion behavior.
Common remote-storage failures
- A DNS, firewall, or routing problem prevents the server from reaching the backend.
- The SSH host key changed, or the service account cannot write to the repository directory.
- Object-storage credentials lack permission to list, read, or create objects.
- A repository is reachable but has no second copy or independent recovery location.
- A slow link causes a timer to overlap with the next backup run.
Exercise
Exercise
Which backend should you choose for Borg when the destination is a second Linux server, and why is a direct S3 URL not equivalent?
Show answer
Use Borg over SSH because Borg expects a local repository or a remote Borg process. A direct S3 URL is not a native Borg repository backend and would require an additional mount or gateway layer.