AKZN Notes

Archives for My Lazy and Forgetful Mind

How to Backup VPS to Home Server using BORG

To back up your VPS to your home server using BorgBackup, follow these steps:


1. Install Borg on Both VPS & Home Server

On VPS:

sudo apt update && sudo apt install borgbackup -y

On Home Server:

sudo apt update && sudo apt install borgbackup -y

2. Set Up SSH Access (Passwordless Login)

On your VPS, generate an SSH key:

ssh-keygen -t ed25519 -C "borg-backup"

Press Enter to accept defaults.

Copy the key to your Home Server:

ssh-copy-id user@home-server

Test SSH login:

ssh user@home-server

If it logs in without a password, SSH is set up.


3. Initialize the Borg Repository on Home Server

On VPS, run:

ssh user@home-server "borg init --encryption=repokey ~/borg-backups"

This initializes ~/borg-backups on your Home Server.


4. Create a Backup from VPS to Home Server

Run this from VPS:

borg create --stats --progress user@home-server:~/borg-backups::backup-$(date +%Y-%m-%d) /important/data
  • Replace /important/data with directories to back up.

5. Automate Backups with Cron

Edit crontab:

crontab -e

Add a daily backup at 2 AM:

0 2 * * * borg create --stats user@home-server:~/borg-backups::backup-$(date +\%Y-\%m-\%d) /important/data

6. Prune Old Backups

To keep 7 daily, 4 weekly, and 6 monthly backups, run:

borg prune -v --list user@home-server:~/borg-backups --keep-daily=7 --keep-weekly=4 --keep-monthly=6

Add this to cron for automatic pruning.


7. Verify Backups

List backups:

borg list user@home-server:~/borg-backups

Restore a file:

borg extract user@home-server:~/borg-backups::backup-YYYY-MM-DD path/to/file

This setup ensures automatic, secure backups from your VPS to your home server. 🚀

Leave a Reply

Your email address will not be published.