54 lines
No EOL
1.8 KiB
Makefile
54 lines
No EOL
1.8 KiB
Makefile
@_default:
|
|
{{just_executable()}} -f {{justfile()}} --list
|
|
|
|
# Run the instance [aliases: r]
|
|
@run:
|
|
sudo docker-compose up -d
|
|
|
|
# Stop the instance [aliases: s]
|
|
@stop:
|
|
sudo docker-compose stop
|
|
|
|
# Restart the instance
|
|
@restart:
|
|
sudo docker-compose restart
|
|
|
|
# Create Backup file [aliases: b]
|
|
@backup backup_name:
|
|
#!/usr/bin/env bash
|
|
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"
|
|
7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -mhe=on -p {{backup_name}}.7z $FILES
|
|
rm -fr $DATABASE_BACKUP_FILE
|
|
echo "Backup done..."
|
|
|
|
# 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..."
|
|
|
|
|
|
[private]
|
|
alias r := run
|
|
[private]
|
|
alias s := stop
|
|
[private]
|
|
alias b := backup
|
|
[private]
|
|
alias re := restore |