Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add backup and restore scripts #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions scripts/backup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Defina as variáveis de conexão com o banco de dados
DB_SERVICE="db"
DB_NAME="pretix"
DB_USER="pretix"

# Caminho para o diretório de backup
BACKUP_DB_FILE="./backup/backup_$(date +"%Y%m%d_%H%M%S").dump"

# Executa dump da base de dados
docker compose exec $DB_SERVICE pg_dump -U $DB_USER -d $DB_NAME > $BACKUP_DB_FILE

echo "Backup $BACKUP_DB_FILE completo!"

# backup dos uploads do pretix
SERVICE_NAME="pretix"
# Nome e caminho completo para o arquivo tar.gz de backup
BACKUP_VOLUME_FILE="./backup/backup_$(date +"%Y%m%d_%H%M%S").tar.gz"

# Compacta e salva o backup dos uploads do pretix
docker compose exec $SERVICE_NAME tar -czf - /data > $BACKUP_VOLUME_FILE

echo "Backup $BACKUP_VOLUME_FILE completo"

25 changes: 25 additions & 0 deletions scripts/restore_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Defina o nome do serviço PostgreSQL no seu arquivo docker-compose.yml
DB_SERVICE="db"
# Defina as credenciais de conexão com o banco de dados
DB_NAME="pretix"
DB_USER="pretix"
DB_PASSWORD="pretixtest"

# Caminho para o arquivo de dump
LATEST_DB_BACKUP=$(ls -t ./backup | grep ".dump$" | head -n 1)

# Restaura o dump para o banco de dados
docker compose exec -T $DB_SERVICE psql -U $DB_USER -d $DB_NAME < ./backup/$LATEST_DB_BACKUP

echo "Restauração $LATEST_BACKUP completa"

SERVICE_NAME="pretix"
# Nome e caminho completo para o arquivo tar.gz de backup
LATEST_VOLUME_BACKUP=$(ls -t ./backup | grep ".tar.gz$" | head -n 1)

# Compacta e salva o backup dos uploads do pretix
docker compose exec $SERVICE_NAME sh -c "tar -xzvf ./backup/$LATEST_VOLUME_BACKUP -C /data"
#docker compose exec $SERVICE_NAME tar -xzf ./backup/$LATEST_VOLUME_BACKUP -C /data