2024-04-13 16:33:38 +02:00
|
|
|
@_default:
|
|
|
|
{{just_executable()}} -f {{justfile()}} --list
|
|
|
|
|
|
|
|
# Run the instance [aliases: r]
|
|
|
|
@run:
|
|
|
|
sudo docker-compose up -d
|
|
|
|
|
|
|
|
# Stop the instance [aliases: s]
|
|
|
|
@stop:
|
2024-05-03 12:22:42 +02:00
|
|
|
sudo docker-compose stop
|
2024-04-13 16:33:38 +02:00
|
|
|
|
|
|
|
# Restart the instance
|
|
|
|
@restart:
|
|
|
|
sudo docker-compose restart
|
|
|
|
|
|
|
|
# Create Backup file [aliases: b]
|
2024-05-03 12:22:42 +02:00
|
|
|
@backup backup_name:
|
2024-04-13 16:33:38 +02:00
|
|
|
#!/usr/bin/env bash
|
2024-05-03 12:22:42 +02:00
|
|
|
DATABASE_BACKUP_FILE="synapse-postgres-backup-$(date +%d-%m-%Y"_"%H%M%S).sql.gz"
|
|
|
|
sudo docker-compose exec postgresql bash -c "export PGPASSWORD=somepassword && pg_dump -U synapse synapse" | \
|
|
|
|
gzip -9 > $DATABASE_BACKUP_FILE
|
|
|
|
FILES="data postgresdata Justfile docker-compose.yml README.md $DATABASE_BACKUP_FILE"
|
2024-04-13 16:33:38 +02:00
|
|
|
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -mhe=on -p {{backup_name}}.7z $FILES
|
2024-05-03 12:22:42 +02:00
|
|
|
rm -fr $DATABASE_BACKUP_FILE
|
2024-04-13 16:33:38 +02:00
|
|
|
echo "Backup done..."
|
|
|
|
|
2024-05-03 12:22:42 +02:00
|
|
|
# Restore Backup file
|
|
|
|
@restore backup_name: stop && run
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
7z x {{backup_name}}.7z -aoa
|
|
|
|
DATABASE_BACKUP_FILE=$(ls synapse-postgres-backup-*.sql.gz)
|
|
|
|
DATABASE_FILE=$(echo $DATABASE_BACKUP_FILE | sed 's/.gz//')
|
|
|
|
# Run the database to write the sql file to the container
|
|
|
|
sudo docker-compose up -d postgresql
|
|
|
|
|
|
|
|
gunzip -k $DATABASE_BACKUP_FILE && \
|
|
|
|
sudo docker cp $DATABASE_FILE postgresql_synapse:/pg-backup.sql && \
|
|
|
|
sudo docker-compose exec postgresql bash -c "export PGPASSWORD=somepassword && dropdb -U synapse synapse --force && createdb -U synapse synapse && psql -U synapse synapse < pg-backup.sql"
|
|
|
|
rm -fr $DATABASE_FILE
|
|
|
|
rm -fr $DATABASE_BACKUP_FILE
|
|
|
|
|
|
|
|
# Stop the database container (it will be started by the run command)
|
|
|
|
sudo docker-compose stop postgresql
|
|
|
|
echo "Restore done..."
|
|
|
|
|
2024-04-13 16:33:38 +02:00
|
|
|
|
|
|
|
[private]
|
|
|
|
alias r := run
|
|
|
|
[private]
|
|
|
|
alias s := stop
|
|
|
|
[private]
|
|
|
|
alias b := backup
|
2024-05-03 12:22:42 +02:00
|
|
|
[private]
|
|
|
|
alias re := restore
|