# 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` 1. Generates a temporary directory. 1. Copies all stack configuration to temporary directory. 1. Copies all docker volumes `/var/lib/docker/volumes` to temporary directory. 1. Copies all data in `/opt` (where host bind mounts should be) to temporary directory. 1. Compresses the temporary directory. 1. Copies the result to the `/backups` folder. 1. Cleans up / removes temporary directory that was created. 1. Restarts all the services. 1. Removes backups older than 7 days. ## 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. ```bash ///docker/backups/ /backups cifs credentials=/path/to/smbcredentials,uid=0,gid=0 0 0 ``` Once that is done: 1. Generate the `/backups` directory `sudo mkdir /backups` 1. Reload the daemon `sudo systemctl daemon-reload` 1. Mount the folder `sudo mount -a` ### Automated Installation Script This repository has an automated installation script that can be ran. ```bash sudo su -c "bash <(wget -qO- https://git.housh.dev/homelab/backup/raw/branch/main/install.sh)" root ``` ## Manual Installation See [installation script](https://git.housh.dev/homelab/backup/src/branch/main/install.sh). ### Setup the backup script ```bash 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. ```bash 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 The backup script also contains a restore command that can restore the stacks and volumes from a backup (hopefully it's never needed!). ### Usage You can use the restore command without an argument to use the last backup as the archive to restore from. ```bash sudo docker-backup restore ``` Or if you'd like to restore using a specific archive then you can pass in argument that contains the path to the backup archive to use. ```bash sudo docker-backup restore /backups/2025-04-21.tar.gz ```