0

I have this line in the file /var/lib/pgsql/data/postgresql.conf:

#  archive_command = ''           # command to use to archive a logfile segment

we need to uncomment the archive_command parameter, and set its value to

'rsync -a %p barman@barman-backup-server-ip:/var/lib/barman/main-db-server/incoming/%f' 

so the expected results will be

archive_command = 'rsync -a %p barman@barman-backup-server-ip:/var/lib/barman/main-db-server/incoming/%f' 

How to perform this by sed or perl one line liner?

other option is just add the line:

archive_command = 'rsync -a %p barman@barman-backup-server-ip:/var/lib/barman/main-db-server/incoming/%f' 

after the line:

#archive_command = ''
peterh
  • 4,953
  • 13
  • 30
  • 44
jango
  • 59
  • 2
  • 3
  • 12

2 Answers2

1

You can use a command like the following to replace the line containing commented archive_command:

sed -e "s|#  archive_command = .*|archive_command = 'rsync -a %p barman@barman-backup-server-ip:/var/lib/barman/main-db-server/incoming/%f'|" /var/lib/pgsql/data/postgresql.conf

You can add -i option for in-place update.

Khaled
  • 36,533
  • 8
  • 72
  • 99
1

You can use sed as you can see in the @Khaled answer, but the best way to do this is to use a configuration management tool like: ansible, chef, puppet...

I would use a template that is managed completly by the configuration management instead of doing a search and replace. I would use search and replace only if I expect the file to be changed by another configuration management or another user.

The problem with most of the scripts is that they are not designed to be idempotent. If you need to change again that parameter you need to change the script. You could write the sed expresion to be idempotent, but this takes a bit more effort.

Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83