content:serverbasics:docker-backup
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Nächste Überarbeitung | Vorherige Überarbeitung | ||
| content:serverbasics:docker-backup [2025/03/26 16:49] – angelegt obel1x | content:serverbasics:docker-backup [2025/12/06 14:19] (aktuell) – [UserIDs in the Borg-Backups] obel1x | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| ====== Docker: Backup ====== | ====== Docker: Backup ====== | ||
| - | In this Chapter we will Backup the Docker- Volumes and the Data of the home- Directory of Docker, that is important. We will NOT do a full Backup of the Server, while Docker can only archive what is accessable by the user of docker (rootless!). | + | In this Chapter we will Backup the Docker- Volumes and the Data of the home- Directory of Docker, that is important. We will NOT do a full Backup of the Server, while Docker can only archive what is accessable by the user docker (rootless!). |
| - | Further we __**will need a working Nextcloud- AIO with working Nextcloud- Backup preconfigured**__ | + | Further we __**will need a working Nextcloud- AIO with working Nextcloud- Backup preconfigured**__ |
| The benefit of this is, that all the contents of docker will be backed up with the right acces-rights and configurations an we can rely on the functionality of NC-AIO here. | The benefit of this is, that all the contents of docker will be backed up with the right acces-rights and configurations an we can rely on the functionality of NC-AIO here. | ||
| + | |||
| + | ===== Setup Scripts ===== | ||
| + | |||
| + | Create the Directory for your Backup- Scripts, e.g. / | ||
| + | |||
| + | Inside that directory, create a file named "'' | ||
| + | < | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | |||
| + | </ | ||
| + | |||
| + | These are the basic Directories of the User. | ||
| + | |||
| + | Than, create a script named " | ||
| + | |||
| + | < | ||
| + | #!/bin/bash | ||
| + | # Will make a Backup of Docker and all Volumes by calling NC-AIO Backup | ||
| + | DIRECTORYFILE=' | ||
| + | #Services and order to stop | ||
| + | declare -a SERVICE=(" | ||
| + | |||
| + | # Set working dir | ||
| + | cd / | ||
| + | # Get all Directories to backup | ||
| + | cat ${DIRECTORYFILE}_initial> | ||
| + | find "/ | ||
| + | |||
| + | # Remove Database- Directories | ||
| + | sed -i '/ | ||
| + | |||
| + | # Make Postgres-Backup of Authentik | ||
| + | ../ | ||
| + | |||
| + | # Copy the file to NC-AIO | ||
| + | echo "The following Directories will be backup up ADDITIONALLY to Nextcloud AIO:" | ||
| + | cat ${DIRECTORYFILE} | ||
| + | docker cp ${DIRECTORYFILE} nextcloud-aio-mastercontainer:/ | ||
| + | docker exec nextcloud-aio-mastercontainer chown www-data: | ||
| + | docker exec nextcloud-aio-mastercontainer chmod o+r / | ||
| + | |||
| + | # Now stop all containers NOT beeing part of NC | ||
| + | for i in " | ||
| + | echo " | ||
| + | cd / | ||
| + | | ||
| + | sleep 1 | ||
| + | done | ||
| + | |||
| + | echo "Now backup is done by AIO" | ||
| + | docker exec -it --env DAILY_BACKUP=1 nextcloud-aio-mastercontainer / | ||
| + | echo "The Log is:" | ||
| + | docker logs nextcloud-aio-borgbackup | ||
| + | |||
| + | # At this Point all Services should be shutdown despite the AIO-Mastercontainer | ||
| + | # while some services tend to hang sometimes, i now want to completely shutdown everything | ||
| + | / | ||
| + | / | ||
| + | # and even kill docker-service and restart again | ||
| + | systemctl --user restart docker | ||
| + | # now, restart first NC-AIO Mastercontainer for further jobs | ||
| + | cd / | ||
| + | / | ||
| + | |||
| + | # Start the NC-AOI Services by AIO | ||
| + | sleep 2 | ||
| + | docker exec -it --env START_CONTAINERS=1 nextcloud-aio-mastercontainer / | ||
| + | |||
| + | # Start Services in reverse order | ||
| + | for ((i=${# | ||
| + | echo " | ||
| + | cd / | ||
| + | | ||
| + | sleep 1 | ||
| + | done | ||
| + | |||
| + | </ | ||
| + | |||
| + | Thats the whole Backup-Script. | ||
| + | |||
| + | ===== Cronjob ===== | ||
| + | |||
| + | Frist, create another file in that Directory e.g. / | ||
| + | < | ||
| + | |||
| + | #!/bin/bash | ||
| + | cd / | ||
| + | ./ | ||
| + | cat docker_backup_cron.log | ||
| + | |||
| + | </ | ||
| + | |||
| + | Use '' | ||
| + | < | ||
| + | 0 3 * * * / | ||
| + | |||
| + | </ | ||
| + | |||
| + | Thats all. Make sure, you recieve Mails for this user. | ||
| + | |||
| + | ===== Restore and UserIDs in the Borg-Backups ===== | ||
| + | |||
| + | Mind, that Borg will store the UID/GID of some file/ | ||
| + | |||
| + | So you cannot restore the Files on your Host and hope, that this will work. To restore these archives, you need (again) a running Nextcloud- AIO and restore the files from that borg- container, that is included there. | ||
| + | < | ||
| + | < | ||
| + | |||
| + | And DO NOT THINK YOU CAN SET USERS MANUALLY LATER on the Hosts Volumes ! → some containers, like FreeIPA do include non-relative symlinks in their data, even pointing to Files on your Host when looking at them from your Host. If you chown them, than HOST SYSTEMFILES will get messed up, maybe rendering your whole Server unusable! | ||
| + | |||
| + | For making restore of Docker- Volumes easy, check out this community-container: | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | This will do the mounts and will make it easy to copy files from borg backup to the volumes. | ||
content/serverbasics/docker-backup.1743004194.txt.gz · Zuletzt geändert: von obel1x
