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

Fix Backup Permission Error on EC2s #1238

Open
CarsonDavis opened this issue Feb 25, 2025 · 1 comment
Open

Fix Backup Permission Error on EC2s #1238

CarsonDavis opened this issue Feb 25, 2025 · 1 comment
Assignees

Comments

@CarsonDavis
Copy link
Collaborator

Description

Backups can be ran using sde_collections/management/commands/database_backup.py. There are instructions for using it in different environments at the top of the file.

However, although it works seamlessly on local, it is encountering a permission error on server environments, such as Staging and Production.

Here is the error for reference

[ec2-user@STAGING sde-indexing-helper]$ docker-compose -f production.yml run --rm django python manage.py database_backup
WARN[0000] volume "sde-indexing-helper_production_postgres_data" already exists but was not created by Docker Compose. Use `external: true` to use an existing volume 
WARN[0000] volume "sde-indexing-helper_production_postgres_data_backups" already exists but was not created by Docker Compose. Use `external: true` to use an existing volume 
WARN[0000] volume "sde-indexing-helper_production_traefik" already exists but was not created by Docker Compose. Use `external: true` to use an existing volume 
WARN[0000] Found orphan containers ([sde_indexing_helper_local_redis]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up. 
[+] Running 1/0
 ⠿ Container sde-indexing-helper-postgres-1  Running                                                                                                                                                                                                             0.0s
PostgreSQL is available
pg_dump: error: could not open output file "/app/backups/staging_backup_20250225.sql": Permission denied
Backup failed: Command '['pg_dump', '-h', 'sde-indexing-helper-staging-db.c3cr2yyh5zt0.us-east-1.rds.amazonaws.com', '-U', 'postgres', '-d', 'sde_staging', '--no-owner', '--no-privileges', '-f', '/app/backups/staging_backup_20250225.sql']' returned non-zero exit status 1.

Implementation Considerations

  • may need to be able to log onto the server in order to actually test the command

Deliverable

The backup code should be updated such that it no longer produces a permission error on severs.

Dependencies

depends on

@Kirandawadi
Copy link
Collaborator

Try

  • Modify the get_backup_filename() function to set appropriate directory permissions.
backup_dir = "/app/backups"
os.makedirs(backup_dir, exist_ok=True)

#Set permissions: Owner and group can read/write, others have no access
os.chmod(backup_dir, 0o770)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants