Files
backup/README.md

2.1 KiB

backup

A script to backup docker volumes and stack configuration on the servers.

What it does

  1. Stops all docker services located in /etc/komodo/stacks
  2. Generates a temporary directory.
  3. Copies all stack configuration to temporary directory.
  4. Copies all docker volumes /var/lib/docker/volumes to temporary directory.
  5. Copies all data in /opt (where host bind mounts should be) to temporary directory.
  6. Compresses the temporary directory.
  7. Copies the result to the /backups folder.
  8. Cleans up / removes temporary directory that was created.
  9. 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:

  1. Generate the /backups directory sudo mkdir /backups
  2. Reload the daemon sudo systemctl daemon-reload
  3. Mount the folder sudo mount -a

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

Setup the backup script

  1. Download the script wget https://git.housh.dev/homelab/backup/raw/branch/main/docker-backup.sh
  2. Add any extra volumes to backup.
  3. Make script executable chmod +x docker-backup.sh
  4. Manually run the script sudo ./docker-backup.sh

Restore

This repository also contains a restore script that can restore the stacks and volumes from a backup (hopefully it's never needed!).

Usage

  1. Download the script wget https://git.housh.dev/homelab/backup/raw/branch/main/docker-restore.sh
  2. Make script executable chmod +x docker-restore.sh
  3. Run the script sudo ./docker-restore.sh /backups/<backup>.tar.gz