This repository contains documentation for the backup strategy used for my Linux systems. It includes information on the tools and processes used for creating and maintaining backups, as well as instructions for restoring from backups in case of a failure or data loss.
- Borg Backup - A deduplicating backup program that supports compression and authenticated encryption.
- Rclone - A command line tool for synchronizing files and directories to and from various cloud storage providers.
sudo apt-get update
sudo apt-get install borgbackupsudo dnf install borgbackupsudo pacman -S borgbackupcurl https://rclone.org/install.sh | sudo bashcurl https://rclone.org/install.sh | sudo bashsudo pacman -S rcloneThe backup script is built in 3 parts:
- Create a new archive using Borg Backup, with the
borg createcommand. - Use rclone to transfer the archive to a remote storage location, with the
rclone copycommand. - Prune old backups, to keep a specified number of backups and to save space, with the
borg prunecommand.
In case of a failure or data loss, backups can be restored using the borg extract command. Detailed instructions for restoring specific files or directories can be found in the Borg Backup documentation.
Alternatively, borg mount can be used for temporal restoration.
In order to run the backup script automatically using systemd, you will need to create two service files: one for the backup service and one for the timer service.
Create a new file named borg-backup.service in the /etc/systemd/system/ directory with the following contents:
[Unit]
Description=Create backup using Borg Backup
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/borg-backup.sh
StandardOutput=file:/var/log/borg-backup.log
StandardError=file:/var/log/borg-backup-error.log
Restart=on-failure
[Install]
WantedBy=multi-user.target- Make sure to adjust the paths and user according to your system setup.
Then, enable the service by running:
sudo systemctl enable borg-backup.serviceCreate a new file named borg-backup.timer in the /etc/systemd/system/ directory with the following contents:
[Unit]
Description=Create backup using Borg Backup
[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target- Make sure to adjust the timing of the backup by modifying the
OnCalendarvalue to fit your needs.
Then, enable the timer by running:
sudo systemctl enable borg-backup.timerYou can check the status of the timer and the service by running:
sudo systemctl status borg-backup.timer
sudo systemctl status borg-backup.serviceThis documentation is intended to serve as a guide for anyone responsible for maintaining and managing backups for our system. It is important to regularly test and verify the backups to ensure that they can be successfully restored in case of a failure or data loss.
- Add more features to the script: dry-run option
- Improve performance of the code
- Add more comments to the code for better readability
- Write more detailed documentation
- Add test cases to ensure reliability
- Add error handling to the
mysqldumpcommand