af5b9f90e603713ba2d563204f8d1f94f0ec99fa
backup
A script to backup docker volumes and stack configuration on the servers.
What it does
- Stops all docker services located in
/etc/komodo/stacks - Generates a temporary directory.
- Copies all stack configuration to temporary directory.
- Copies all docker volumes
/var/lib/docker/volumesto temporary directory. - Copies all data in
/opt(where host bind mounts should be) to temporary directory. - Compresses the temporary directory.
- Copies the result to the
/backupsfolder. - Cleans up / removes temporary directory that was created.
- Restarts all the services.
Setup
Before using the backup script, you must mount a network share for backups to be
stored in. This is done by editing the /etc/fstab file, and adding the
following line.
//<nas_ip>/docker/backups/<machine> /backups cifs credentials=/home/michael/smbcredentials,uid=0,gid=0 0 0
Once that is done:
- Generate the
/backupsdirectorysudo mkdir /backups - Reload the daemon
sudo systemctl daemon-reload - Mount the folder
sudo mount -a
Automated Installation Script
This repository has an automated installation script that can be ran.
sudo su -c "bash <(wget -qO- https://git.housh.dev/homelab/backup/raw/branch/main/install.sh)" root
Manual Installation
See installation script.
Setup the backup script
sudo wget "https://git.housh.dev/homelab/backup/raw/branch/main/docker-backup.sh" -O /usr/local/bin/docker-backup
sudo chmod +x /usr/local/bin/docker-backup
Systemd Setup
Setup the systemd service and timer, so that backups are ran once a day @ 3 a.m.
cd /etc/systemd/system
sudo wget https://git.housh.dev/homelab/backup/raw/branch/main/backup.service
sudo wget https://git.housh.dev/homelab/backup/raw/branch/main/backup.timer
sudo systemctl daemon-reload
sudo systemctl start backup.timer
sudo systemctl start backup.service
Restore
This repository also contains a restore script that can restore the stacks and volumes from a backup (hopefully it's never needed!).
Usage
- Download the script
wget https://git.housh.dev/homelab/backup/raw/branch/main/docker-restore.sh - Make script executable
chmod +x docker-restore.sh - Run the script
sudo ./docker-restore.sh /backups/<backup>.tar.gz
Languages
Shell
100%