PostgreSQL のベース バックアップを実行しようとしています。私のコードは、Ruby で実行される単純な Bash です。ベースバックアップを実行し、それを /tmp/(DIR) に tar します。
file "/tmp/basebackup.sh" do
user "postgres"
mode 0755
content <<-EOH
su - postgres
export PATH=$PATH:/usr/lib/postgresql/9.2/bin
su -c "/usr/lib/postgresql/9.2/bin/initdb -D /tmp/pg_data/ -s --no-locale --encoding=UTF8" - postgres
su -c "/usr/lib/postgresql/9.2/bin/pg_ctl -D /tmp/pg_data -l logfile start" - postgres
su -c "/usr/lib/postgresql/9.2/bin/psql -c "SELECT pg_start_backup('initial backup for SR')" template1" - postgres
tar -cvf pg_base_backup.tar /tmp/pg_data
su -c "/usr/lib/postgresql/9.2/bin/psql -c "SELECT pg_stop_backup()" template1" - postgres
exit 0
EOH
end
execute "/tmp/basebackup.sh" do
ignore_failure true
action :run
end
これを行うより良い方法はありますか?