Added backup playbook

This commit is contained in:
epickiwi committed 2026-11-07 14:53:28 +01:00
1 parent 82f5efd2ec
commit 25ec8bb21d
7 files changed
+173

No files matched your search

@@ -0,0 +1,6 @@
[Unit]
Description=Advertize pending packup
[Service]
Type=oneshot
ExecStart=/bin/bash /opt/backup/advertize-pending-backup.sh
@@ -0,0 +1,13 @@
#!/bin/bash
BACKUP_DIR="/opt/backup/pending"
UNIFIEDPUSH_TOPIC="https://push.epickiwi.fr/hP4ByeeTDeLmCCPN-sauvegardes-mel"
PENDING_BACKUP_COUNT=$( find "$BACKUP_DIR" -type f | grep -e '\.tar\(.gz\)*$' | wc -l )
if [[ "$PENDING_BACKUP_COUNT" -gt 0 ]]; then
curl -d "$(hostname --long): $PENDING_BACKUP_COUNT pending backups" "$UNIFIEDPUSH_TOPIC"
echo "Advertized $PENDING_BACKUP_COUNT panding backup"
else
echo "There is no pending backup"
fi
@@ -0,0 +1,9 @@
[Unit]
Description=Remind of pending timer every day
[Timer]
OnCalendar=*-*-* 09:00:00
Persistent=true
[Install]
WantedBy=timers.target
+7
View File
@@ -0,0 +1,7 @@
[Unit]
Description=Produce backup archive
[Service]
Type=oneshot
ExecStart=/bin/bash /opt/backup/make-backup.sh
ExecStart=systemctl start advertize-pending-backup.service
+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
## Directory where backup tar.gz files will be created into at the end of backup packaging process
PENDING_BACKUP_DIR="/opt/backup/pending"
## Directory where intermediate artifacts will be placed for backup
CURRENT_BACKUP_DIR="/opt/backup/current"
## File to include into backups
BACKUP_FILES=(
# "/var/lib/conduwuit" managed manually, please do not add in this list
"/srv/www/medicenlutte.fr"
"/opt/backup/current"
)
## Backup date in path-colplient format
DATE=$(date '+%FT%H-%M-%S')
## Final backup file name
BACKUP_FILENAME="backup-$(hostname --long)-$DATE.tar"
# logging tool
LOG="tee -a $CURRENT_BACKUP_DIR/backup.log"
# Removing previous backup if there is some
rm -f -r "$CURRENT_BACKUP_DIR/*"
mkdir -p "$CURRENT_BACKUP_DIR"
mkdir -p "$PENDING_BACKUP_DIR"
# Lezgo
echo "Starting backup $BACKUP_FILENAME" | $LOG
# Backup of continuwuity database
echo "Backing up continuwuity database"
systemctl stop conduwuit 2>&1 | $LOG
tar -r -v -f "$PENDING_BACKUP_DIR/$BACKUP_FILENAME" /var/lib/conduwuit 2>&1 | $LOG
tar -r -v -f "$PENDING_BACKUP_DIR/$BACKUP_FILENAME" /var/lib/private/conduwuit 2>&1 | $LOG
systemctl start conduwuit 2>&1 | $LOG
# Backup of files
for i in $(seq -w "${#BACKUP_FILES[@]}"); do
FILENAME="files-$i.tar"
SRC="${BACKUP_FILES[$(expr $i - 1)]}"
echo "Backing up $FILENAME: $SRC" | $LOG
tar -r -v -f "$PENDING_BACKUP_DIR/$BACKUP_FILENAME" $SRC 2>&1 | $LOG
done
tar -r -v -f "$PENDING_BACKUP_DIR/$BACKUP_FILENAME" "$CURRENT_BACKUP_DIR/backup.log"
gzip "$PENDING_BACKUP_DIR/$BACKUP_FILENAME" | $LOG
rm -rf "$CURRENT_BACKUP_DIR/*"
+9
View File
@@ -0,0 +1,9 @@
[Unit]
Description=Produce backup archive every month
[Timer]
OnCalendar=Wed *-*-1..7 12:00:00
Persistent=true
[Install]
WantedBy=timers.target