1
0
mirror of https://github.com/xzeldon/vwdump.git synced 2025-06-28 02:28:14 +03:00
vwdump/script.sh
jmqm 479d78b9e3
Combine scripts, refactor, minor README improvements (#26)
- Combined backup and delete scripts.
  - Consequently, deleted `backup.sh` and `delete.sh`.
  - Changed Dockerfile and `entrypoint.sh`.
- Refactored script.
- Docker compose example in README now includes network property _(is it called a property?)_.
- README volume permission requirements are placed at better locations.
2022-01-02 19:37:08 -06:00

43 lines
1.3 KiB
Bash

#!/bin/sh
# --------------- [ PREREQUISITES ] ---------------
EXTENSION="tar.xz"
# ------------------ [ BACKUP ] ------------------
cd /data
BACKUP_LOCATION="/backups/$(date +"%F_%H-%M-%S").${EXTENSION}"
BACKUP_DB="db.sqlite3" # file
BACKUP_RSA="rsa_key*" # files
BACKUP_CONFIG="config.json" # file
BACKUP_ATTACHMENTS="attachments" # directory
BACKUP_SENDS="sends" # directory
# Back up files and folders.
tar -Jcf $BACKUP_LOCATION $BACKUP_DB $BACKUP_RSA $BACKUP_CONFIG $BACKUP_ATTACHMENTS $BACKUP_SENDS 2>/dev/null
OUTPUT="${OUTPUT}New backup created"
# ------------------ [ DELETE ] ------------------
if [ -n "$DELETE_AFTER" ] && [ "$DELETE_AFTER" -gt 0 ]; then
cd /backups
# Find all archives older than x days, store them in a variable, delete them.
TO_DELETE=$(find . -iname "*.${EXTENSION}" -type f -mtime +$DELETE_AFTER)
find . -iname "*.${EXTENSION}" -type f -mtime +$DELETE_AFTER -exec rm -f {} \;
OUTPUT="${OUTPUT}, $([ ! -z "$TO_DELETE" ] \
&& echo "deleted $(echo "$TO_DELETE" | wc -l) archives older than ${DELETE_AFTER} days" \
|| echo "no archives older than ${DELETE_AFTER} days to delete")"
fi
# ------------------ [ EXIT ] ------------------
echo "[$(date +"%F %r")] ${OUTPUT}."