How to organize automatic backup of PostgreSQL databases using cron?

0 like 0 dislike
11 views
Good day, to create a backup of Postgres database using the command
networks pg_dump > /DATA/backups/gitlab'date +%d-%m-%Y`

Everything works as desired, but if I put this command in cron, this command drops the mail in /var/mail/postgres with the error text

/bin/sh: 1: Syntax error: EOF in backquote substitution

I understand that something is not right in the syntax, but how to fix this error? Thank you in advance all for the help
by | 11 views

1 Answer

0 like 0 dislike
Read man 5 crontab and see there
Percent-signs (%) in the command, unless escaped with backslash \\, will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

That is, the percent sign in a configuration file cron is perceived as a newline character. To avoid this it is necessary to screen a back slash.
networks pg_dump > /DATA/backups/gitlab'date +\\%d-\\%m-\\%Y`
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
7 answers
asked Apr 4, 2019 by Indermove
0 like 0 dislike
7 answers
asked Apr 1, 2019 by Indermove
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
32,718 users