0

I am taking a dump of database as below:

pg_dump -c -p 5432 <DB_NAME>| zip --encrypt Name.zip -

I don't want to use minus '-' sign for stdin; instead I want to use a filename with date for daily backups.

I tried few things but to no avail.

  • Is my answer below satisfactory? If so, please consider accepting it with the checkmark. Thank you! – Jeff Schaller Aug 27 '17 at 1:27
1

Since you're piping data to zip, all it has is stdin. If you want a filename for zip, then you'll have to create & use one:

filename=$(date +%Y%m%d.dump)
pg_dump -c -p 5432 <DB_NAME> -f "$filename" &&
  zip --encrypt Name.zip "$filename" &&
rm "$filename"
  • Thanks Jeff it works however, the only reason i wanted to avoid minus "-" is when i unzip the file it unzip the files as minus sign. – nmm18 Aug 18 '17 at 19:34
  • If that's the only reason, then consider unzipping the file using -p ala this answer – Jeff Schaller Aug 18 '17 at 19:50
  • If (from your answer/edit) you're looking to automate the password entry, consider the --password option to zip, along with it's warnings. – Jeff Schaller Aug 18 '17 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.