[init]
This commit is contained in:
92
restore.sh
Normal file
92
restore.sh
Normal file
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# =============================================================================
|
||||
# Gitea Restore Script for Dokploy
|
||||
# =============================================================================
|
||||
#
|
||||
# Prerequisites:
|
||||
# - Dokploy is installed and running
|
||||
# - The Gitea compose stack is deployed (first boot completed)
|
||||
# - You have gitea_db_backup.dump and gitea_files_backup.tar.gz in ~/
|
||||
# - Your app.ini (with real secrets) is in ~/
|
||||
#
|
||||
# Usage:
|
||||
# chmod +x restore.sh
|
||||
# ./restore.sh
|
||||
#
|
||||
# =============================================================================
|
||||
|
||||
# --- Configuration ---
|
||||
# Update these if your container names differ
|
||||
GITEA_CONTAINER="gitea"
|
||||
DB_CONTAINER="gitea-db"
|
||||
DB_USER="gitea"
|
||||
DB_NAME="gitea"
|
||||
|
||||
BACKUP_DIR="$HOME"
|
||||
DB_DUMP="$BACKUP_DIR/gitea_db_backup.dump"
|
||||
FILES_BACKUP="$BACKUP_DIR/gitea_files_backup.tar.gz"
|
||||
APP_INI="$BACKUP_DIR/app.ini"
|
||||
|
||||
# --- Preflight checks ---
|
||||
echo "=== Preflight checks ==="
|
||||
|
||||
for file in "$DB_DUMP" "$FILES_BACKUP" "$APP_INI"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
echo "ERROR: $file not found"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${DB_CONTAINER}$"; then
|
||||
echo "ERROR: Container $DB_CONTAINER is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${GITEA_CONTAINER}$"; then
|
||||
echo "ERROR: Container $GITEA_CONTAINER is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "All checks passed."
|
||||
|
||||
# --- Restore database ---
|
||||
echo ""
|
||||
echo "=== Restoring database ==="
|
||||
docker cp "$DB_DUMP" "$DB_CONTAINER":/tmp/gitea_db_backup.dump
|
||||
docker exec -it "$DB_CONTAINER" pg_restore \
|
||||
-U "$DB_USER" -d "$DB_NAME" \
|
||||
--no-owner --no-acl \
|
||||
/tmp/gitea_db_backup.dump
|
||||
echo "Database restored."
|
||||
|
||||
# --- Restore files ---
|
||||
echo ""
|
||||
echo "=== Restoring files ==="
|
||||
docker cp "$FILES_BACKUP" "$GITEA_CONTAINER":/tmp/gitea_files_backup.tar.gz
|
||||
docker exec -it "$GITEA_CONTAINER" bash -c '
|
||||
cd /tmp
|
||||
tar xzf gitea_files_backup.tar.gz --strip-components=3
|
||||
cp -r repositories /data/git/
|
||||
[ -d lfs ] && cp -r lfs /data/git/
|
||||
[ -d avatars ] && cp -r avatars /data/gitea/
|
||||
[ -d attachments ] && cp -r attachments /data/gitea/
|
||||
chown -R git:git /data/git /data/gitea
|
||||
rm -rf /tmp/repositories /tmp/lfs /tmp/avatars /tmp/attachments /tmp/gitea_files_backup.tar.gz
|
||||
'
|
||||
echo "Files restored."
|
||||
|
||||
# --- Inject app.ini ---
|
||||
echo ""
|
||||
echo "=== Injecting app.ini ==="
|
||||
docker cp "$APP_INI" "$GITEA_CONTAINER":/data/gitea/conf/app.ini
|
||||
echo "Config injected."
|
||||
|
||||
# --- Restart ---
|
||||
echo ""
|
||||
echo "=== Restarting Gitea ==="
|
||||
docker restart "$GITEA_CONTAINER"
|
||||
echo "Done! Gitea should be available shortly."
|
||||
echo ""
|
||||
echo "Verify with: curl -s http://\$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $GITEA_CONTAINER):3000 | head -5"
|
||||
Reference in New Issue
Block a user