Project Overview
This project implemented a fully automated, peer-to-peer, encrypted, and highly scalable backup solution using restic. Restic is a modern backup program that provides fast, secure, and efficient backups to a variety of storage backends. The solution was designed to automatically back up critical directories on a regular schedule, ensuring data integrity and availability.
What is Restic?
Restic is a program that does backups right. It is designed to be:
- Secure: All data is encrypted using AES-256 in counter mode.
- Efficient: Only changes are backed up (deduplication), saving space and bandwidth.
- Fast: Uses concurrent processing and efficient algorithms.
- Verifiable: Backups can be checked for integrity at any time.
- Easy: Simple command-line interface and automation-friendly.
Advantages Over Other Backup Systems
- End-to-End Encryption: Unlike rsync or tar, restic encrypts data before it leaves your machine.
- Deduplication: Only stores unique data chunks, reducing storage needs.
- Snapshot-Based: Each backup is a snapshot, making restores easy and reliable.
- Multi-Backend Support: Works with local storage, SFTP, REST, S3, and more.
- No Client-Server Model: No need for a central backup server; ideal for peer-to-peer setups.
Automated Backup Scripts
1. Backup /home Directories 4 Times a Day (Business Hours)
#!/bin/bash
# Script: backup_home.sh
# Description: Backup all user home directories 4 times a day during business hours
# Usage: Add to cron as: 0 8,11,14,17 * * 1-5 /path/to/backup_home.sh
LOG_FILE="/var/log/restic_home_backup.log"
REPO="/mnt/backup/restic_home"
PASSWORD_FILE="/etc/restic/home_pass"
# Initialize repository if not exists
if ! restic -r "$REPO" cat config >/dev/null 2>&1; then
echo "$(date) - Initializing restic repository at $REPO" >> "$LOG_FILE"
restic -r "$REPO" init
fi
# Backup each user's home directory
for user in $(ls /home); do
echo "$(date) - Backing up /home/$user" >> "$LOG_FILE"
restic -r "$REPO" --password-file="$PASSWORD_FILE" backup /home/$user
restic -r "$REPO" --password-file="$PASSWORD_FILE" forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
done
echo "$(date) - Home backup completed" >> "$LOG_FILE"
2. Backup /etc, /usr, /var, /opt Every Friday After 5:30 PM
#!/bin/bash
# Script: backup_system.sh
# Description: Backup system directories every Friday after 5:30 PM
# Usage: Add to cron as: 30 17 * * 5 /path/to/backup_system.sh
LOG_FILE="/var/log/restic_system_backup.log"
REPO="/mnt/backup/restic_system"
PASSWORD_FILE="/etc/restic/system_pass"
# Initialize repository if not exists
if ! restic -r "$REPO" cat config >/dev/null 2>&1; then
echo "$(date) - Initializing restic repository at $REPO" >> "$LOG_FILE"
restic -r "$REPO" init
fi
# Backup system directories
echo "$(date) - Backing up system directories" >> "$LOG_FILE"
restic -r "$REPO" --password-file="$PASSWORD_FILE" backup /etc /usr /var /opt
restic -r "$REPO" --password-file="$PASSWORD_FILE" forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
echo "$(date) - System backup completed" >> "$LOG_FILE"
Technical Stack
Restic
Linux (Debian/Ubuntu)
Bash Scripting
Cron
AES-256 Encryption
SFTP/REST/S3 Backends