backup_postgresql.sh 473 B

1234567891011121314
  1. #!/bin/bash
  2. #Source external configuration
  3. . $1
  4. today=$(date +"%Y-%m-%d_%H-%M")
  5. filename="${today}_${dbName}_Backup.sql"
  6. fullBackupFileName="${backupFilepath}${filename}"
  7. #Backup Job
  8. docker exec -i ${dockerContainerName} /bin/bash -c "PGPASSWORD=${dbpasswd} pg_dump --username ${dbUser} ${dbName}" > $fullBackupFileName
  9. #Backup rotation - Delete everything older than rotationDays
  10. find $backupFilepath -type f -mtime +$rotationDays -name '*.sql' -execdir rm -- '{}' \;