Borg is a popular open-source deduplicating backup program that can be used to backup your data from your local machine to a remote server, such as your home server. Here is a step-by-step guide on how to set up Borg on your home server to act as a backup server:
- Install Borg on your local machine and home server:
You can install Borg on your local machine and home server using the package manager of your choice. For example, on Ubuntu, you can use the following command:
sudo apt-get install borgbackup
- Create a new backup repository on your home server:
You can create a new backup repository on your home server using the borg init command. For example:
ssh username@homeserver borg init --encryption=repokey /path/to/backup/repo
This command initializes a new backup repository at /path/to/backup/repo with the repokey encryption.
3. Configure SSH access:
To make it easier to backup your data to your home server, you can configure SSH access so that you don't need to enter your password every time you run a backup. You can do this by creating a new SSH key pair on your local machine and adding the public key to the authorized_keys file on your home server.
On your local machine, run the following command to create a new SSH key pair:
ssh-keygen -t rsa
This will create two files in the ~/.ssh directory: id_rsa (the private key) and id_rsa.pub (the public key). You can then copy the public key to your home server by running the following command:
ssh-copy-id username@homeserver
- Create a backup script:
You can create a backup script that will backup your data to your home server. Here is an example backup script:
#!/bin/bash
# Set the backup directory and repository
BACKUP_DIR="/path/to/backup/data"
REPO="/path/to/backup/repo"
# Create a timestamp for the backup archive
DATE=$(date +%Y-%m-%d-%H%M%S)
# Create the backup archive
borg create --verbose \
--compression lz4 \
--progress \
--timestamp "$DATE" \
--exclude-caches \
"$REPO::$DATE" \
"$BACKUP_DIR"
# Display the backup statistics
borg info "$REPO::$DATE"
This script will backup the data in the /path/to/backup/data directory to the backup repository at /path/to/backup/repo. It will create a new backup archive with a timestamp and use the lz4 compression algorithm. It will also exclude any cache files from the backup.
5. Run the backup script:
You can run the backup script manually or schedule it to run automatically using cron. For example, to run the backup script every night at 3am, you can add the following line to your crontab file:
0 3 * * * /path/to/backup/script.sh
This will run the backup script at 3am every day.
6. Restore data:
To restore your data from the backup repository, you can use the borg extract command. For example, to restore the backup from yesterday, you can run the following command:
borg extract --verbose /path/to/backup/repo::yesterday /path/to/restore/data
This will extract the backup from yesterday and restore it to the /path/to/restore/data directory.
That's it! You have successfully set up Borg on your home server to act as a backup server.