Docker Consolidation Project, Part Seven

Docker Consolidation Project, Part Seven
Photo by Jess Bailey / Unsplash

I'm going to start today by setting up some backups on DOCKER-01.

Backup Actual

So I better get a backup script up and running for Actual Budget. I write up a draft in Github called actual-backup.sh

#!/bin/bash

### actual-backup.sh - Backup script for the Actual Budget application
## This script will make a backup of the Actual Budget configuration files

# Create a copy of the code data for Actual Budget
cp -R /apps/Actual-Budget/actual-data/server-files /home/david/Backups/Actual-Budget/server-files-`date +%F`
cp -R /apps/Actual-Budget/actual-data/user-files /home/david/Backups/Actual-Budget/user-files-`date +%F`

# Create a copy of the Actual Budget docker-compose.yml file
cp /apps/Actual-Budget/docker-compose.yml /home/david/Backups/Actual-Budget/docker-compose.yml-`date +%F`

# Compress and archive all the files
tar -czvf /home/david/Backups/Actual-Budget/Archive/actual-backup-`date +%F`.tar.gz /home/david/Backups/Actual-Budget/server-files-`date +%F` /home/david/Backups/Actual-Budget/user-files-`date +%F` /home/david/Backups/Actual-Budget/docker-compose.yml-`date +%F`

# Remove temporary files
rm -R /home/david/Backups/Actual-Budget/server-files-`date +%F` /home/david/Backups/Actual-Budget/user-files-`date +%F` /home/david/Backups/Actual-Budget/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/Actual-Budget/Archive/ /mnt/Backups/domain.local/Applications/Actual-Budget/

Steps performed on DOCKER-01

  • mkdir /home/david/Actual-Budget
  • mkdir /home/david/Actual-Budget/Archive
  • sudo mkdir /mnt/Backups
  • nano /home/david/.win/_service_backups-credentials
username=_service_backups
password=
domain=domain.local
  • I saved the _service_backups-credentials file
  • chmod 600 /home/david/.win/_service_backups-credentials
  • sudo nano /etc/fstab
  • I add the following:
# Mount for backing up to fileserver
//10.10.10.XXX/Data/Files/Backups/domain.local /mnt/Backups cifs credentials=/home/david/.win/_service_backups-credentials,uid=1000,gid=1000,iocharset=utf8
  • I saved fstab

I already have cifs-utils installed on DOCKER-01 since I have the network shares opened for applications.

  • ls /mnt/Backups
    • Applications Servers
  • sudo nano /usr/bin/actual-backup
#!/bin/bash

### actual-backup.sh - Backup script for the Actual Budget application
## This script will make a backup of the Actual Budget configuration files

# Create a copy of the code data for Actual Budget
cp -R /apps/Actual-Budget/actual-data/server-files /home/david/Backups/Actual-Budget/server-files-`date +%F`
cp -R /apps/Actual-Budget/actual-data/user-files /home/david/Backups/Actual-Budget/user-files-`date +%F`

# Create a copy of the Actual Budget docker-compose.yml file
cp /apps/Actual-Budget/docker-compose.yml /home/david/Backups/Actual-Budget/docker-compose.yml-`date +%F`

# Compress and archive all the files
tar -czvf /home/david/Backups/Actual-Budget/Archive/actual-backup-`date +%F`.tar.gz /home/david/Backups/Actual-Budget/server-files-`date +%F` /home/david/Backups/Actual-Budget/user-files-`date +%F` /home/david/Backups/Actual-Budget/docker-compose.yml-`date +%F`

# Remove temporary files
rm -R /home/david/Backups/Actual-Budget/server-files-`date +%F` /home/david/Backups/Actual-Budget/user-files-`date +%F` /home/david/Backups/Actual-Budget/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/Actual-Budget/Archive/ /mnt/Backups/domain.local/Applications/Actual-Budget/
  • I save the actual-backup file
  • sudo chmod +x /usr/bin/actual-backup
  • sudo nano /etc/crontab and add the following:
# Script to backup Actual-Budget
6 0 * * 5  root    /usr/bin/actual-budget
  • I save the crontab file

Backup Authentik

So here's my draft of authentik-backup.sh

#!/bin/bash

### authentik-backup.sh - Backup script for the Authentik Security application
## This script will make a backup of the Authentik Security configuration files

# Create a copy of the code data for Authentik Security
cp -R /apps/Authentik-Security/. /home/david/Backups/Authentik-Security/Authentik-Security-`date +%F`
cp -R /var/lib/docker/volumes/authentik-security_database/. /home/david/Backups/Authentik-Security/authentik-security_database-`date +%F`
cp -R /var/lib/docker/volumes/authentik-security_redis/. /home/david/Backups/Authentik-Security/authentik-security_redis-`date +%F`

# Create a copy of the Authentik Security Docker Compose file
cp /apps/Authentik-Security/docker-compose.yml /home/david/Backups/Authentik-Security/docker-compose.yml-`date +%F`

# Compress and archive all the files
tar -czvf /home/david/Backups/Authentik-Security/Archive/authentik-backup-`date +%F`.tar.gz /home/david/Backups/Authentik-Security/Authentik-Security-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_database-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_redis-`date +%F` /home/david/Backups/Authentik-Security/docker-compose.yml-`date +%F`

# Remove temporary files
rm -R /home/david/Backups/Authentik-Security/Authentik-Security-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_database-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_redis-`date +%F` /home/david/Backups/Authentik-Security/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/Authentik-Security/Archive/ /mnt/Backups/domain.local/Applications/Authentik-Security/

Steps performed on DOCKER-01

  • mkdir /home/david/Backups/Authentik-Security
  • mkdir /home/david/Backups/Authentik-Security/Archive
  • sudo nano /usr/bin/authentik-backup
#!/bin/bash

### authentik-backup.sh - Backup script for the Authentik Security application
## This script will make a backup of the Authentik Security configuration files

# Create a copy of the code data for Authentik Security
cp -R /apps/Authentik-Security/. /home/david/Backups/Authentik-Security/Authentik-Security-`date +%F`
cp -R /var/lib/docker/volumes/authentik-security_database/. /home/david/Backups/Authentik-Security/authentik-security_database-`date +%F`
cp -R /var/lib/docker/volumes/authentik-security_redis/. /home/david/Backups/Authentik-Security/authentik-security_redis-`date +%F`

# Create a copy of the Authentik Security Docker Compose file
cp /apps/Authentik-Security/docker-compose.yml /home/david/Backups/Authentik-Security/docker-compose.yml-`date +%F`

# Compress and archive all the files
tar -czvf /home/david/Backups/Authentik-Security/Archive/authentik-backup-`date +%F`.tar.gz /home/david/Backups/Authentik-Security/Authentik-Security-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_database-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_redis-`date +%F` /home/david/Backups/Authentik-Security/docker-compose.yml-`date +%F`

# Remove temporary files
rm -R /home/david/Backups/Authentik-Security/Authentik-Security-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_database-`date +%F` /home/david/Backups/Authentik-Security/authentik-security_redis-`date +%F` /home/david/Backups/Authentik-Security/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/Authentik-Security/Archive/ /mnt/Backups/domain.local/Applications/Authentik-Security/
  • I save authentik-security
  • sudo chmod +x /urs/bin/authentik-backup
  • sudo nano /etc/crontab
# Script to backup Authentik-Security
8 0 * * 5  root    /usr/bin/authentik-backup
  • I save the file crontab

Backup Homebox

Steps performed on DOCKER-01

  • mkdir /home/david/Backups/Homebox-Inventory
  • mkdir /home/david/Backups/Homebox-Inventory/Archive
  • sudo nano /usr/bin/homebox
#!/bin/bash

### homebox-backup.sh - Backup script for the Homebox Inventory application
## This script will make a backup of the Homebox database and configuration files

# Create a copy of the Homebox database
cp /var/lib/docker/volumes/homebox-inventory_homebox-data/_data/homebox.db /home/david/Backups/Homebox-Inventory/homebox.db-`date +%F`
cp /var/lib/docker/volumes/homebox-inventory_homebox-data/_data/homebox.db-shm /home/david/Backups/Homebox-Inventory/homebox.db-shm-`date +%F`
cp /var/lib/docker/volumes/homebox-inventory_homebox-data/_data/homebox.db-wal /home/david/Backups/Homebox-Inventory/homebox.db-wal-`date +%F`

# Create a copy of Homebox docker-compose.yml
cp /apps/Homebox-Inventory/docker-compose.yml /home/david/Backups/Homebox-Inventory/docker-compose.yml-`date +%F`

# Compress and archive all the files
tar -czvf /home/david/Backups/Homebox-Inventory/Archive/homebox-backup-`date +%F`.tar.gz /home/david/Backups/Homebox-Inventory/homebox.db-`date +%F` /home/david/Backups/Homebox-Inventory/homebox.db-shm-`date +%F` /home/david/Backups/Homebox-Inventory/homebox.db-wal-`date +%F` /home/david/Backups/Homebox-Inventory/docker-compose.yml-`date +%F`

# Remove the temporary backup files
rm -R /home/david/Backups/Homebox-Inventory/homebox.db-`date +%F` /home/david/Backups/Homebox-Inventory/homebox.db-shm-`date +%F` /home/david/Backups/Homebox-Inventory/homebox.db-wal-`date +%F` /home/david/Backups/Homebox-Inventory/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/Homebox-Inventory/Archive/ /mnt/Backups/domain.local/Applications/Homebox-Inventory/
  • I save the file homebox-backup
  • sudo chmod +x /usr/bin/homebox-backup
  • sudo nano /etc/crontab
# Script to backup Homebox-Inventory
9 0 * * 5  root    /usr/bin/homebox-backup
  • I save the file crontab

Backup Paperless-NGX

Steps performed on DOCKER-01

  • mkdir /home/david/Backups/Paperless-NGX
  • mkdir /home/david/Backups/Paperless-NGX/Archive
  • sudo nano /usr/bin/paperless-backup
#!/bin/bash

### paperless-backup.sh - Backup script for the Paperless-NGX application
## This script will make a backup of the Paperless-NGX configuration files
## Data for this backup process was collected from:
## https://paperless-ngx.readthedocs.io/en/latest/administration.html#making-backups

# Create a copy of docker-compose.yml
cp /apps/Paperless-NGX/docker-compose.yml /home/david/Backups/Paperless-NGX/docker-compose.yml-`date +%F`

# Create a copy of docker-compose.env
cp /apps/Paperless-NGX/docker-compose.env /home/david/Backups/Paperless-NGX/docker-compose.env-`date +%F`

# Create a copy and compress the three docker volumes
# Note that paperless_media is actually mounted elsewhere and as such is actually stored on FNKY-FS-02 and is backed up from that server.
tar -czvf /home/david/Backups/Paperless-NGX/paperless_redisdata-`date +%F`.tar.gz /var/lib/docker/volumes/paperless_redisdata/
tar -czvf /home/david/Backups/Paperless-NGX/paperless_dbdata-`date +%F`.tar.gz /var/lib/docker/volumes/paperless_dbdata/
tar -czvf /home/david/Backups/Paperless-NGX/paperless_data-`date +%F`.tar.gz /var/lib/docker/volumes/paperless_data/

# Compress all volumes and files.
tar -czvf /home/david/Backups/Paperless-NGX/Archive/paperless-backup-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/paperless_redisdata-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/paperless_dbdata-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/paperless_data-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/docker-compose.env-`date +%F` /home/david/Backups/Paperless-NGX/docker-compose.yml-`date +%F`

# Remove all temporary files
rm -R /home/david/Backups/Paperless-NGX/paperless_redisdata-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/paperless_dbdata-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/paperless_data-`date +%F`.tar.gz /home/david/Backups/Paperless-NGX/docker-compose.env-`date +%F` /home/david/Backups/Paperless-NGX/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/Paperless-NGX/Archive/ /mnt/Backups/domain.local/Applications/Paperless-NGX/
  • I save the paperless-backup file
  • sudo chmod +x /usr/bin/paperless-backup
  • sudo nano /etc/crontab
# Script to backup Paperless-NGX
10 0 * * 5  root   /usr/bin/paperless-backup
  • I save the file crontab

Backup PhotoPrism

Steps performed on DOCKER-01

  • mkdir /home/david/Backups/PhotoPrism
  • mkdir /home/david/Backups/PhotoPrism/Archive
  • sudo nano /usr/bin/photoprism-backup
#!/bin/bash

### photoprism-backup.sh - Backup script for the PhotoPrism application
## This script will make a backup of the PhotoPrism database and configuration files.

# Create a backup of the database
docker-compose exec -T photoprism photoprism backup -i - > /home/david/Backups/PhotoPrism/photoprism-db-`date +%F`.sql

# Create a backup of PhotoPrism storage folder
# Since the majority of the storage folder is thumbnails in cache and sidecar I do not need a running changelog of thumbnails. So this will not have a dated file name.
tar -czvf /home/david/Backups/PhotoPrism/storage.tar /apps/PhotoPrism/storage

# Create a backup of docker compose .yml file
cp /apps/PhotoPrism/docker-compose.yml /home/david/Backups/PhotoPrism/docker-compose-`date +%F`.yml

# Create the final archive
mv /home/david/Backups/PhotoPrism/storage.tar /home/david/Backups/PhotoPrism/Archive/storage.tar
tar -czvf /home/david/Backups/PhotoPrism/Archive/photoprism-`date +%F`.tar /home/david/Backups/PhotoPrism/photoprism-db-`date +%F`.sql /home/david/Backups/PhotoPrism/docker-compose-`date +%F`.yml

# Clean up temporary files
rm /home/david/Backups/PhotoPrism/photoprism-db-`date +%F`.sql /home/david/Backups/PhotoPrism/docker-compose-`date +%F`.yml

# Copy backup to fileserver
rsync -avh /home/david/Backups/PhotoPrism/Archive/ /mnt/Backups/domain.local/Applications/PhotoPrism/
  • I save the file paperless-backup
  • sudo chmod +x /usr/bin/paperless-backup
  • sudo nano /etc/crontab
# Script to backup PhotoPrism
15 0 * * 5  root   /usr/bin/photoprism-backup

Backup Tandoor Recipes

Steps performed on DOCKER-01

  • mkdir /home/david/Backups/Tandoor-Recipes
  • mkdir /home/david/Backups/Tandoor-Recipes/Archive
  • sudo nano /usr/bin/tandoor-backup
#!/bin/bash

### tandoor-backup.sh
## This script will make a backup of the Tandoor Recipe software

# Create a copy of the database for Tandoor Recipes
sudo docker exec -t tandoor-recipes_db_recipes_1 pg_dumpall -U djangouser > /home/david/Backups/Tandoor-Recipes/tandoor-recipes-db-`date +%F`.sql

# Create a copy of the Tandoor Recipe docker-compose.yml
cp /apps/Tandoor-Recipes/docker-compose.yml /home/david/Backups/Tandoor-Recipes/docker-compose-`date +%F`.yml

# Compress and archive all the files
tar -czvf /home/david/Backups/Tandoor-Recipes/Archive/tandoor-backup-`date +%F`.tar.gz /home/david/Backups/Tandoor-Recipes/tandoor-recipes-db-`date +%F`.sql /home/david/Backups/Tandoor-Recipes/docker-compose-`date +%F`.yml

# Remove temporary files
rm -R /home/david/Backups/Tandoor-Recipes/tandoor-recipes-db-`date +%F`.sql /home/david/Backups/Tandoor-Recipes/docker-compose-`date +%F`.yml

# Copy backup to fileserver
rsync -avh /home/david/Backups/Tandoor-Recipes/Archive/ /mnt/Backups/domain.local/Applications/Tandoor-Recipes/
  • I save tandoor-backup
  • sudo chmod +x /usr/bin/tandoor-backup
  • sudo nano /etc/crontab
# Script to backup Tandoor-Recipe
26 0 * * 5 root    /usr/bin/tandoor-backup
  • I save crontab

Backup TubeArchivist

  • mkdir /home/david/Backups/TubeArchivist
  • mkdir /home/david/Backups/TubeArchivist/Archive
  • sudo nano /usr/bin/tubearchivist-backup
#!/bin/bash

### tubearchivist-backup.sh - Backup script for TubeArchivist
## This script will make a backup of the TubeArchivist database and configuration files.

# Create a copy of TubeArchivist docker-compose.yml
cp /apps/TubeArchivist/docker-compose.yml /home/david/Backups/TubeArchivist/docker-compose.yml-`date +%F`

# Create a copy of TubeArchivist database
cp /apps/TubeArchivist/cache/db.sqlite3 /home/david/Backups/TubeArchivist/db.sqlite3-`date +%F`

# Compress and archive all the files
tar -czvf /home/david/Backups/TubeArchivist/Archive/tubearchivist-backup-`date +%F`.tar.gz /home/david/Backups/TubeArchivist/docker-compose.yml-`date +%F` /home/david/Backups/TubeArchivist/db.sqlite3-`date +%F`

# Remove the temporary backup file
rm -R /home/david/Backups/TubeArchivist/db.sqlite3-`date +%F` /home/david/Backups/TubeArchivist/docker-compose.yml-`date +%F`

# Copy backup to fileserver
rsync -avh /home/david/Backups/TubeArchivist/Archive/ /mnt/Backups/domain.local/Applications/TubeArchivist/
  • I save tubearchivist-backup
  • sudo chmod +x /usr/bin/tubearchivist-backup
  • sudo nano /etc/crontab
# Script to backup TubeArchive
27 0 * * 5 root    /usr/bin/tubearchivist-backup
  • I save crontab

This feels like it will be a very boring blog post. Backups seem to always be that way. People always struggle to assess future risk, and then compound the issue by procrastinating due to the risk being at some point in the future. It's important to have everyone buy in to a policy of just making sure backups happen. Then you don't have to worry about it again.