Skip to content

Commit

Permalink
Merge pull request #96 from mjanez/ckan-2.9.9
Browse files Browse the repository at this point in the history
Fix bash script to backup ckan db
  • Loading branch information
mjanez authored Nov 23, 2023
2 parents da0f7b6 + 49b9be0 commit 69217a4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,31 @@ PostgreSQL offers the command line tools [`pg_dump`](https://www.postgresql.org/

2. Add the following code to the script, replacing the placeholders with your actual values:

```sh
```bash
#!/bin/bash
# Set the necessary variables
POSTGRESQL_CONTAINER_NAME="db"
DATABASE_NAME="ckan"
POSTGRES_USER="ckan"
CONTAINER_NAME="db"
DATABASE_NAME="ckandb"
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="your_postgres_password"
BACKUP_DIRECTORY="/path/to/your/backup/directory"
DATE=$(date +%Y%m%d%H%M%S)
MONTH=$(date +%m)
YEAR=$(date +%Y)
# Create the monthly backup directory if it doesn't exist
mkdir -p "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH"
# Run the backup command
docker exec -e PGPASSWORD=$POSTGRES_PASSWORD $POSTGRESQL_CONTAINER_NAME pg_dump -U $POSTGRES_USER -Fc $DATABASE_NAME > $BACKUP_DIRECTORY/ckan_backup_$DATE.dump
docker exec -e PGPASSWORD=$POSTGRES_PASSWORD $CONTAINER_NAME pg_dump -U $POSTGRES_USER -Fc $DATABASE_NAME > "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH/ckan_backup_$DATE.dump"
# Compress the dump files into a zip archive
cd "$BACKUP_DIRECTORY/monthly/$YEAR-$MONTH" || exit
zip "backup_${YEAR}-${MONTH}.zip" *.dump
# Remove the original dump files
rm -f *.dump
```

3. Replace the following placeholders with your actual values:
Expand Down

0 comments on commit 69217a4

Please sign in to comment.