pg_dump: too many command-line arguments (first is "--host=localhost") - python

I have gone through some similar question on SO but didn't find any workable solutions.
I tried using djang-dbbackup module with my Django project.
I run $ python manage.py dbbackup and got this error:
CommandConnectorError: Error running: pg_dump last_cosmetics --host=localhost --username=postgres --no-password --clean
b'pg_dump: too many command-line arguments (first is "--host=localhost")\r\nTry "pg_dump --help" for more information.\r\n'
Also I tried running it on Windows cmd.
pg_dump last_cosmetics --host=localhost --username=postgres --no-password --clean
But I still get the same error.

You can check syntax in here.
Database name should be last argument after all options.
So in your case use:
pg_dump --host=localhost --username=postgres --no-password --clean last_cosmetics

If you used user as postgres in CentOS then
su postgres
pg_dump -Fc last_cosmetics > /tmp/last_cosmetics.dump
It works in Ubuntu too.

Related

mysqldump command working in cmd but not in python

I'm trying to do some tests dumping data from one database to another with mysqldump.
The mysqldump is set in PATH, and the command runs perfectly in the CMD interface, or via a .cmd.
It seems to run ok in python wrapped in a simple try/except block, but I don't get any result in the target database.
Working with:
MariaDB 10.1 & 10.5 /
Python 3.9
The command looks similar to this:
mysqldump --no-create-info --no-create-db --user root -p****** --port=some_port -h 127.0.0.1 some_database some_table |
mysql --user root -p***** --port=some_port -h 127.0.0.1 target_table
What I've tried is different variations on Popen (also trying to handle the pipe via subprocess, and splitting the args), but starting with the simplest soltuion given elsewhere on stackoverflow:
subprocess.Popen("mysqldump --no-create-info --no-create-db --user root -p****** --port=some_port -h 127.0.0.1 some_database some_table |
mysql --user root -p***** --port=some_port -h 127.0.0.1 target_table", shell=True)
I also made a .cmd file and ran this in windows and it works fine. Passing it to either Popen() or os.system() in python gives the same problem, seems to check out in a try/except, but no result seen in the target database.
What could be the problem, and how do I get this right?
Solved for anyone who wants to know.
Put the absolute paths in the command with the short names generated for non-8dot3 file names like so:
'C:\\PROGRA~1\\MARIAD~1.1\\bin\\mysqldump.exe --no-create-info --no-create-db --user root -p****** --port=some_port -h 127.0.0.1 some_database some_table |
C:\\PROGRA~1\\MARIAD~1.1\\bin\\mysql.exe --user root -p****** --port=some_port -h 127.0.0.1 some_database'
It's my work laptop where they only give permissions to add to PATH on my user account, and not the entire system. Got my Python configured to look at system PATH.
Was a bit confusing to see it work in the command line and a .cmd script, but in no way in Python. And when running, not telling me it isn't "recognized as an internal command..." when in other cases it does.

Cannot restore postgres dump on heroku

I am using this command to create dump locally
PGPASSWORD=admin pg_dump -h 127.0.0.1 -p 5432 -U postgres --no-owner --no-acl -f database.dump and my is created successfully.
then uploaded this dump to dropbox and make it public with this link http://www.dropbox.com/s/rsqeiuqzusejz5x/database.dump?dl=1 notice I have changed https to http and dl=0 to dl=1 (dl=1 to make it downloadable)
then on my terminal I am running this command heroku pg:backups:restore "http://www.dropbox.com/s/38prh2y7pdwhqqj/database.dump?dl=1" --confirm tranquil-anchorage-39635
but I am getting this error
! An error occurred and the backup did not finish.
!
! pg_restore: error: did not find magic string in file header
! waiting for restore to complete
! pg_restore finished with errors
! waiting for download to complete
! download finished successfully
!
! Run heroku pg:backups:info r010 for more details.
I have tried all the official documentation and various answers but nothing seems to work.
On doing further research I found out that pg_restore command while restoring dump file expects a certain format that must be mentioned while creating the dump file. That is why there was an error pg_restore: error: did not find magic string in file header.
pg_dump -h <localhost> -p <port> -U <username> --format=c <database_name> > daman.dump
after running this command you will be prompt to enter the password for the user.
Notice --format=c in the above command. This will create a dump file in a format that can be restored by pg_restore, also I should mention that the dump file created in this manner is not readable to text-editor like notepad or vscode unlike the in the case when --format=c is not used.
for further details see the documentation here
I found that even with the correct file format, only certain file hosts would work. I tried file.io and filetransfer.io, but neither one seemed to work with Heroku. Only Amazon S3 worked correctly of those three.
Even if you have the correct file format, you'll get this error if you try to host the file in certain places.
Try to run pg_dump with -Fc option (customized format
) as documented in https://devcenter.heroku.com/articles/heroku-postgres-import-export:
pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump

Django: dbbackup displays pg_dump: error: too many command-line arguments

I've installed the django-dbbackup package and from what the Documentation tells, i need to run python manage.py dbbackup
but it generated error pg_dump: error: too many command-line arguments
from what i have seen in the logs
dbbackup.db.exceptions.CommandConnectorError: Error running: pg_dump database_name --host=127.0.0.1 --port=5432 --username=postgres --no-password --clean
From what i have known, the correct command for pg_dump is to include the database name in the last part but the dbbackup include the database name first.
Anyone know the fix for the Django-dbbackup?
I had the same error. What I did was
Made sure pg_dump was in the environment variable in my system.
pip uninstall dbbackup
pip install django-dbbackup --upgrade
And it worked!
I have same issue with you, this is my env
Window 10
postgres10
django 2.2.9
django-dbbackup 3.2.0
I can manual run successfully like below, add "--dbname" parm name.
pg_dump --dbname=database_name --host=127.0.0.1 --port=5432 --username=postgres --no-password --clean
I don't know how to override the command by create a new method, so I changed the source code in dbbackup package directly, it works.
file "\Lib\site-packages\dbbackup\db\postgresql.py"
from:
cmd = '{} --dbname={}'.format(self.dump_cmd, self.settings['NAME'])
to:
cmd = '{} {}'.format(self.dump_cmd, self.settings['NAME'])

PostgreSQL on MacOSX

I just wanted to install a PostgreSQL Database. After 3 hours of trying I do not know what else to do. My last try included installing PostgreSQL via Homebrew -> Works perfectly fine.
But typing this:
which psql
I got this: /usr/local/bin/psql
From my view this sort of Path is wrong, a I saw a different one in most tutorials. But I have no idea what to do.
But I went on trying:
createuser -U postgres yrkIO -P
And the terminal asked me for a password only to give me this:
createuser: could not connect to database postgres: FATAL: role "postgres" does not exist
What can I do, I just want to run a PostgreSQL on my Python Flask App?
Have you tried it without forcing a password?
createuser -s -r postgres
This worked for me.
Also, remember to start a server
Start:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Stop server:
pg_ctl -D /usr/local/var/postgres stop -s -m fast

how can i use python to deploy proxies from the command line

Deployment by using Python throws error:
I used Python code ( its your deploy.py) to deploy our proxy (our company proxy) into apigee platform. i read http://apigee.com/docs/api-services/content/deploying-proxies-command-line
but it throws error when i run "python api-platform-samples-master/tools/deploy.py -n apikey -u "yusuf.karatoprak#mobgen.com:Welcome#2014" -o yusufkaratoprak123 -e test -p / -d sample-proxies"
i would like to solve this situation. i added to python code it is not working. it throws me Error: name 'ZipFile' is not defined
The -d flag value needs to point to the directory that contains the /apiproxy directory for the sample you want to deploy. (In your command above, it appears that you are pointing at /sample-proxies, rather than, for example, /sample-proxies/apikey
Try using the deploy scripts. There is one in each sample proxy directory. There's a also a script, /setup/deploy_all.sh if you want to deploy all sample proxies.
Make sure you update /setup/setenv.sh before running the deploy scripts.
The error is in how you are calling it from the command line. You have a space in one of the parameters you pass in, which needs to be put inside of quotes. Turn -u yusuf karatoprak:123 into -u "yusuf karatoprak:123"
Fixed command line call:
python api-platform-samples-master/tools/deploy.py -n weatherapi -u "yusuf karatoprak:123" -o yk123 -e test -p / -d simpleProxy

Categories

Resources