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