feat: Cleanup and updates readme.
This commit is contained in:
51
README.md
51
README.md
@@ -1,13 +1,52 @@
|
|||||||
# backup
|
# backup
|
||||||
|
|
||||||
A script template to backup docker volumes on the servers.
|
A script to backup docker volumes and stack configuration on the servers.
|
||||||
|
|
||||||
## Usage
|
## 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.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
//<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`
|
||||||
|
1. Reload the daemon `sudo systemctl daemon-reload`
|
||||||
|
1. 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.
|
||||||
|
|
||||||
|
```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
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setup the backup script
|
||||||
|
|
||||||
1. Download the script `wget https://git.housh.dev/homelab/backup/raw/branch/main/docker-backup.sh`
|
1. Download the script `wget https://git.housh.dev/homelab/backup/raw/branch/main/docker-backup.sh`
|
||||||
1. Edit the script to include services that need to be shut down, prior to
|
|
||||||
backup.
|
|
||||||
1. Add any extra volumes to backup.
|
1. Add any extra volumes to backup.
|
||||||
1. Make script executable `chmod +x docker-backup.sh`
|
1. Make script executable `chmod +x docker-backup.sh`
|
||||||
1. Run the script `sudo ./docker-backup.sh`
|
1. Manually run the script `sudo ./docker-backup.sh`
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
today=$(date +'%F')
|
today=$(date +'%F')
|
||||||
volumesdir="/var/lib/docker/volumes"
|
|
||||||
stackdir="/etc/komodo/stacks"
|
stackdir="/etc/komodo/stacks"
|
||||||
backupdir="/backups"
|
backupdir="/backups"
|
||||||
|
services=($(find "$stackdir" -maxdepth 1 -mindepth 1 -type d))
|
||||||
# Add services here to stop and backup.
|
|
||||||
services=(
|
|
||||||
"$stackdir/caddy_housh_dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add volumes here to backup.
|
# Add volumes here to backup.
|
||||||
volumes=(
|
volumes=(
|
||||||
"$volumesdir"
|
"/var/lib/docker/volumes"
|
||||||
|
"/opt"
|
||||||
)
|
)
|
||||||
|
|
||||||
function stopServices() {
|
function stopServices() {
|
||||||
@@ -49,11 +45,11 @@ function copyVolumes() {
|
|||||||
|
|
||||||
function backup() {
|
function backup() {
|
||||||
echo "Creating backup..."
|
echo "Creating backup..."
|
||||||
tar -cvf "/tmp/$today.tar" "$1"
|
tar -cvf "/$today.tar" "$1"
|
||||||
gzip "/tmp/$today.tar"
|
gzip "/$today.tar"
|
||||||
cp -R "/tmp/$today.tar.gz" "$backupdir"
|
cp -R "/$today.tar.gz" "$backupdir"
|
||||||
# Cleanup temporary files.
|
# Cleanup temporary files.
|
||||||
rm -rf "$temp" "/tmp/$today.tar" "/tmp/$today.tar.gz"
|
rm -rf "$1" "/$today.tar" "/$today.tar.gz"
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user