gitea/backup.sh.save

22 lines
618 B
Bash

#!/bin/bash
BACKUP_DIR="/backup/$(date +%F_%H-%M)/"
DB_BACKUP_FILE="$BACKUP_DIR/gitea.sql"
$container_id = docker ps --filter "name=^gitea$" -q
$user = docker inspect -f '{{json .Config.Env}}' $container_id | jq -r '.[] | select(startswith("USER=")) | split("=")[1]'
PGPASSWORD="$DB_PASSWORD" pg_dump -h database -U $DB_USER -d $DB_DATABASE -F c -b -v -f $DB_BACKUP_FILE
TARGET_PATH="s3://$BACKUP_SPACE_NAME/backups/$(date +%F_%H-%M)"
BACKUP_FILE=$(date +%F_%H-%M)
tar -czf "backup"
s3cmd put --encrypt $BACKUP_DIR* $TARGET_PATH --recursive
rm -rf $BACKUP_DIR
echo "Files have been uploaded to $TARGET_PATH"