You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.0 KiB
Markdown

4 years ago
# BorgBackup in docker
###### guide by example
4 years ago
![logo](https://i.imgur.com/dR50bkP.png)
4 years ago
4 years ago
# purpose
Backups.
4 years ago
* [Official site](https://www.borgbackup.org/)
* [Github](https://github.com/borgbackup/borg)
4 years ago
# files and directory structure
4 years ago
4 years ago
```
4 years ago
/home/
└── ~/
├── borg/
│ ├── docker_backup/
│ ├── borg_backup.sh
│ └── borg_backup.log
4 years ago
4 years ago
└── docker/
4 years ago
├── container-setup #1
├── container-setup #2
4 years ago
├── ...
4 years ago
```
4 years ago
4 years ago
# The setup
4 years ago
4 years ago
BorgBackup is installed directly on the host system.</br>
A script is created that backs up the entire docker directory locally.</br>
4 years ago
Cronjob is executing this script daily.
4 years ago
4 years ago
#### • Install BorgBackup
4 years ago
4 years ago
#### • Create a new borg repo
`mkdir ~/borg`</br>
`borg init --encryption=none ~/borg/docker_backup`
4 years ago
4 years ago
#### • The script
4 years ago
4 years ago
`borg_backup.sh`
```bash
#!/bin/bash
4 years ago
4 years ago
# INITIALIZE THE REPO WITH THE COMMAND:
# borg init --encryption=none ~/borg/my_backup
# THEN RUN THIS SCRIPT
4 years ago
4 years ago
# -----------------------------------------------
4 years ago
4 years ago
BACKUP_THIS='/home/bastard/docker /etc'
REPOSITORY='/home/bastard/borg/docker_backup'
LOGFILE='/home/bastard/borg/borg_backup.log'
4 years ago
4 years ago
# -----------------------------------------------
4 years ago
4 years ago
NOW=$(date +"%Y-%m-%d | %H:%M | ")
echo "$NOW Starting Backup and Prune" >> $LOGFILE
4 years ago
4 years ago
# CREATES NEW ARCHIVE IN PRESET REPOSITORY
4 years ago
4 years ago
borg create \
$REPOSITORY::'{now:%s}' \
$BACKUP_THIS \
\
--compression zstd \
--one-file-system \
--exclude-caches \
--exclude-if-present '.nobackup' \
--exclude '/home/*/Downloads/' \
4 years ago
4 years ago
# DELETES ARCHIVES NOT FITTING KEEP-RULES
4 years ago
4 years ago
borg prune -v --list $REPOSITORY \
--keep-daily=7 \
--keep-weekly=4 \
--keep-monthly=6 \
--keep-yearly=0 \
4 years ago
4 years ago
echo "$NOW Done" >> $LOGFILE
echo '------------------------------' >> $LOGFILE
4 years ago
4 years ago
# --- USEFULL SHIT ---
4 years ago
4 years ago
# setup above ignores directories containing '.nobackup' file
# make '.nobackup' imutable using chattr to prevent accidental removal
# touch .nobackup
# chattr +i .nobackup
4 years ago
4 years ago
# in the repo folder, to list available backups:
# borg list .
# to mount one of them:
# borg mount .::1584472836 ~/temp
# to umount:
# borg umount ~/temp
# to delete single backup in a repo:
# borg delete .::1584472836
```
4 years ago
4 years ago
the script must be **executabe** - `chmod +x borg_backup.sh`
4 years ago
4 years ago
#### • Automatic execution
4 years ago
cron job, every day at 3:00</br>
4 years ago
`crontab -e`</br>
4 years ago
`0 3 * * * /home/bastard/borg/borg_backup.sh`
4 years ago
# Remote backup
4 years ago
4 years ago
Backing up borg repo to a network share or cloud using rclone
4 years ago
4 years ago
*To be continued*