selfhosted-apps-docker/borg_backup/readme.md

115 lines
3.1 KiB
Markdown
Raw Normal View History

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