cookiecutter-django
cookiecutter-django copied to clipboard
Can't backup PostgreSQL in Docker Environment
What happened?
Can't backup PostgreSQL in Docker Environment
I have got a dev environment in Windows (PyCharm), so when I first tried to do a backup or view backups I got /usr/bin/env: ‘bash\r’: No such file or directory
.
After running sudo find . -type f -exec dos2unix {} \;
in compose folder I now get:
$ sudo docker-compose -f production.yml run --rm postgres backup
Creating site_postgres_run ... done
/usr/local/bin/docker-entrypoint.sh: line 315: /usr/local/bin/backup: Success
ERROR: 1
If I use exec
(stated in the docs) nothing happens.
Checking backups works:
$ sudo docker-compose -f production.yml run --rm postgres backups
Creating site_postgres_run ... done
These are the backups you have got:
total 0
What should've happened instead?
Backing up the 'my_project' database...
SUCCESS: 'my_project' database backup 'backup_2018_03_13T09_05_07.sql.gz' has been created and placed in '/backups'.
Additional details
I didn't change any files inside the compose folder. Please let me know which logs would be relevant (I tried running in verbose but it doesn't seem relevant).
* postgres:12.3
* Docker version (if using Docker), run `docker --version`: Docker version 20.10.4, build d3cb89e
* docker-compose version (if using Docker), run `docker-compose --version`: docker-compose version 1.28.6, build 5db8d86f
Trying using ls
in place of backup to see if the SQL file is stuck in the Postgres container
Hi @Andrew-Chen-Wang, sorry for the delay. The backups directory is empty.
$ ls -l
total 0
This is an windows issue.
Your remote git repo is on Linux linux line endings. When you check it out, windows converts the line endings to CR-LF.
You can supress the issue if you check out with git clone [email protected]:xxxx/django.git --config core.autocrlf=input
I would suggest adding something like
RUN find /usr/local/bin/maintenance/ -type f -exec sed -i 's/\r$//g' {}
in the postgres dockerfile to clean up file endings in all maintenance scripts like in the django docker file done with entrypoint and start script.