44 lines
1.4 KiB
Bash
Executable File
44 lines
1.4 KiB
Bash
Executable File
# mailcow-local-backup.sh
|
|
#!/bin/bash
|
|
|
|
# This script is setup to use a mailcow.email script to create to backup
|
|
|
|
# Use your health check url
|
|
HEALTHCHECK_URL="https://healthchecks.io/ping/{uuid}"
|
|
|
|
PATH_TO_MAILCOW_BACKUP_SCRIPT="/root/docker/mailcow-dockerized/helper-scripts"
|
|
|
|
curl --retry 3 "$HEALTHCHECK_URL/start" || exit 1
|
|
|
|
DATE1=$(date +"%Y-%m-%d-%H-%M-")
|
|
|
|
# Set backup locations
|
|
LOCAL_BACKUP_LOCATION="/root/s3_backup/mailcow"
|
|
|
|
# Change to Mailcow directory and create local backup
|
|
cd /root/docker/mailcow-dockerized || exit 1
|
|
BACKUP_LOCATION=$LOCAL_BACKUP_LOCATION /bin/bash $PATH_TO_MAILCOW_BACKUP_SCRIPT/backup_and_restore.sh backup all || exit 1
|
|
|
|
# Check if Restic is installed, if not install it
|
|
if ! command -v restic &> /dev/null
|
|
then
|
|
echo "Restic is not installed, installing now..."
|
|
sudo apt-get update || exit 1
|
|
sudo apt-get install restic -y || exit 1
|
|
echo "Restic installed."
|
|
fi
|
|
|
|
# Restic backup
|
|
export RESTIC_REPOSITORY="s3:https://eu-central-1.linodeobjects.com/{BucketName}"
|
|
export RESTIC_PASSWORD="{RESTIC_PASSWORD}"
|
|
export AWS_ACCESS_KEY_ID="{AWS_ACCESS_KEY_ID}"
|
|
export AWS_SECRET_ACCESS_KEY="{AWS_SECRET_ACCESS_KEY}"
|
|
|
|
# Sync to S3
|
|
restic backup $LOCAL_BACKUP_LOCATION --tag {customTag}
|
|
|
|
# Clean S3 up
|
|
restic forget --tag {customTag} --prune --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 10
|
|
|
|
# Remove local backup after synchronization to S3
|
|
rm -rf "$LOCAL_BACKUP_LOCATION/*" || exit 1 |