From f9a556740917233232a9b9c942679e47be1771e675c4c09ae3385434a07583f0 Mon Sep 17 00:00:00 2001 From: Marcus Rueckert Date: Fri, 18 Feb 2022 17:58:46 +0000 Subject: [PATCH] - add systemd services: - diff/full/incremental backup - pgbackrest services for the TLS server - add pgbackrest.target to restart/stop all sub services - add Requires(pre) for postgresql-server to make sure the postgresql user is available for file permissions - change permissions of the config file from 0644 to 0640 as the file can contain passwords and encryption keys. - modernize the spec file OBS-URL: https://build.opensuse.org/package/show/server:database:postgresql/pgbackrest?expand=0&rev=43 --- pgbackrest-diff@.service | 15 ++++ pgbackrest-diff@.timer | 14 ++++ pgbackrest-full@.service | 15 ++++ pgbackrest-full@.timer | 14 ++++ pgbackrest-incr@.service | 15 ++++ pgbackrest-incr@.timer | 13 ++++ pgbackrest.changes | 13 ++++ pgbackrest-conf.patch => pgbackrest.conf | 0 pgbackrest.service | 18 +++++ pgbackrest.spec | 88 +++++++++++++++++++----- pgbackrest.target | 3 + 11 files changed, 189 insertions(+), 19 deletions(-) create mode 100644 pgbackrest-diff@.service create mode 100644 pgbackrest-diff@.timer create mode 100644 pgbackrest-full@.service create mode 100644 pgbackrest-full@.timer create mode 100644 pgbackrest-incr@.service create mode 100644 pgbackrest-incr@.timer rename pgbackrest-conf.patch => pgbackrest.conf (100%) create mode 100644 pgbackrest.service create mode 100644 pgbackrest.target diff --git a/pgbackrest-diff@.service b/pgbackrest-diff@.service new file mode 100644 index 0000000..ca90491 --- /dev/null +++ b/pgbackrest-diff@.service @@ -0,0 +1,15 @@ +[Unit] +Description=pgbackrest backup diff for %i +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +ConditionACPower=true +PartOf=pgbackrest.target + +[Service] +Type=oneshot +User=postgres +Group=postgres +ExecStart=/usr/bin/pgbackrest --log-level-console=info --stanza=%i --type=diff backup +# Give a reasonable amount of time for job to finish +TimeoutSec=7200 + diff --git a/pgbackrest-diff@.timer b/pgbackrest-diff@.timer new file mode 100644 index 0000000..e58eb0b --- /dev/null +++ b/pgbackrest-diff@.timer @@ -0,0 +1,14 @@ +[Unit] +Description=Weekly pgbackrest diff backup (sun) +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +PartOf=pgbackrest.target + +[Timer] +#OnCalendar=Sun *-*-8..31 05:05:05 +OnCalendar=Wed *-*-* 05:05:05 +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/pgbackrest-full@.service b/pgbackrest-full@.service new file mode 100644 index 0000000..99ae9f6 --- /dev/null +++ b/pgbackrest-full@.service @@ -0,0 +1,15 @@ +[Unit] +Description=pgbackrest backup full for %i +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +ConditionACPower=true +PartOf=pgbackrest.target + +[Service] +Type=oneshot +User=postgres +Group=postgres +ExecStart=/usr/bin/pgbackrest --log-level-console=info --stanza=%i --type=full backup +# Give a reasonable amount of time for the job to run before timeout +TimeoutSec=7200 + diff --git a/pgbackrest-full@.timer b/pgbackrest-full@.timer new file mode 100644 index 0000000..9b1e46b --- /dev/null +++ b/pgbackrest-full@.timer @@ -0,0 +1,14 @@ +[Unit] +Description=Montly pgbackrest full backup (1st sun) +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +PartOf=pgbackrest.target + +[Timer] +#OnCalendar=Sun *-*-1..7 05:05:05 +OnCalendar=Sun *-*-* 05:05:05 +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/pgbackrest-incr@.service b/pgbackrest-incr@.service new file mode 100644 index 0000000..d33cffd --- /dev/null +++ b/pgbackrest-incr@.service @@ -0,0 +1,15 @@ +[Unit] +Description=pgbackrest backup incremental for %i +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +ConditionACPower=true +PartOf=pgbackrest.target + +[Service] +Type=oneshot +User=postgres +Group=postgres +ExecStart=/usr/bin/pgbackrest --log-level-console=info --stanza=%i --type=incr backup +# Give a reasonable amount of time for the job to finish +TimeoutSec=7200 + diff --git a/pgbackrest-incr@.timer b/pgbackrest-incr@.timer new file mode 100644 index 0000000..d11ca5a --- /dev/null +++ b/pgbackrest-incr@.timer @@ -0,0 +1,13 @@ +[Unit] +Description=Daily pgbackrest incremental backup (mon-sat) +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +PartOf=pgbackrest.target + +[Timer] +OnCalendar=Mon..Sat *-*-* 05:05:05 +AccuracySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/pgbackrest.changes b/pgbackrest.changes index 84c0c4f..7749c06 100644 --- a/pgbackrest.changes +++ b/pgbackrest.changes @@ -1,3 +1,16 @@ +------------------------------------------------------------------- +Fri Feb 18 17:48:11 UTC 2022 - Marcus Rueckert + +- add systemd services: + - diff/full/incremental backup + - pgbackrest services for the TLS server + - add pgbackrest.target to restart/stop all sub services +- add Requires(pre) for postgresql-server to make sure the + postgresql user is available for file permissions +- change permissions of the config file from 0644 to 0640 as the + file can contain passwords and encryption keys. +- modernize the spec file + ------------------------------------------------------------------- Tue Jan 25 13:27:08 UTC 2022 - Marcus Rueckert diff --git a/pgbackrest-conf.patch b/pgbackrest.conf similarity index 100% rename from pgbackrest-conf.patch rename to pgbackrest.conf diff --git a/pgbackrest.service b/pgbackrest.service new file mode 100644 index 0000000..eef8eae --- /dev/null +++ b/pgbackrest.service @@ -0,0 +1,18 @@ +[Unit] +Description=pgBackRest Server +Documentation=https://pgbackrest.org/configuration.html +Documentation=man:pgbackrest(1) man:pgbackrest.conf(5) +After=network.target +StartLimitIntervalSec=0 +PartOf=pgbackrest.target + +[Service] +Type=simple +Restart=always +RestartSec=1 +User=postgres +ExecStart=/usr/bin/pgbackrest server +ExecReload=kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/pgbackrest.spec b/pgbackrest.spec index f0e5d1b..86b8a46 100644 --- a/pgbackrest.spec +++ b/pgbackrest.spec @@ -1,7 +1,7 @@ # # spec file for package pgbackrest # -# Copyright (c) 2021 SUSE LLC +# Copyright (c) 2022 SUSE LLC # Copyright (c) 2019-2021 Ioda-Net Sàrl, Charmoille, Switzerland. # # All modifications and additions to the file contributed by third parties @@ -16,6 +16,7 @@ # Please submit bugfixes or comments via https://bugs.opensuse.org/ # +%define services pgbackrest.target pgbackrest-diff@.service pgbackrest-full@.service pgbackrest-incr@.service pgbackrest.service pgbackrest-diff@.timer pgbackrest-full@.timer pgbackrest-incr@.timer Name: pgbackrest Version: 2.37 @@ -25,16 +26,34 @@ License: MIT Group: Productivity/Databases/Tools URL: http://www.pgbackrest.org Source: https://github.com/pgbackrest/pgbackrest/archive/release/%{version}/%{name}-%{version}.tar.gz -Source1: pgbackrest-conf.patch +Source1: pgbackrest.conf + +Source10: pgbackrest-diff@.service +Source11: pgbackrest-diff@.timer +Source12: pgbackrest-full@.service +Source13: pgbackrest-full@.timer +Source14: pgbackrest-incr@.service +Source15: pgbackrest-incr@.timer +Source16: pgbackrest.service +Source17: pgbackrest.target + Patch0: libpq-fe.h_localisation.patch BuildRequires: libyaml-devel BuildRequires: openssl-devel BuildRequires: pkgconfig BuildRequires: pkgconfig(bzip2) +%if 0%{?suse_version} >= 1500 BuildRequires: pkgconfig(liblz4) +%endif BuildRequires: pkgconfig(libpq) BuildRequires: pkgconfig(libxml-2.0) +%if 0%{?is_opensuse} || 0%{?sle_version} >= 150100 BuildRequires: pkgconfig(libzstd) +%endif +BuildRequires: pkgconfig(systemd) + +# This is a bit awkward as we only need this for directory ownership +Requires(pre): postgresql-server %description pgBackRest aims to be a simple, reliable backup and restore system for @@ -58,41 +77,72 @@ The following features are available: - Compatibility with PostgreSQL >= 8.3 %prep -%setup -q -n %{name}-release-%{version} -%autopatch -p1 -pushd src -%configure -popd +%autosetup -p1 -n %{name}-release-%{version} %build -# TODO upstream doesn't care about RPM_OPT_FLAGS -export CFLAGS="%optflags" pushd src -%make_build +%configure +# make_build doesn't work on sle12, as long we want to support that we can not use the macro here +make %{?_smp_mflags} popd %install -install -D -d -m 0700 %{buildroot}/%{_localstatedir}/lib/%{name} -install -D -d -m 0700 %{buildroot}%{_localstatedir}/log/%{name} -install -D -d -m 0700 %{buildroot}%{_localstatedir}/spool/%{name} -install -D -d -m 0755 %{buildroot}%{_sysconfdir} -install %{SOURCE1} %{buildroot}/%{_sysconfdir}/%{name}.conf -make install -C src DESTDIR=%{buildroot} +%make_install -C src + +install -D -d -m 0700 \ + %{buildroot}%{_localstatedir}/lib/%{name} \ + %{buildroot}%{_localstatedir}/log/%{name} \ + %{buildroot}%{_localstatedir}/spool/%{name} + +install -D -d -m 0755 \ + %{buildroot}%{_sysconfdir} \ + %{buildroot}%{_unitdir} + +install -m 0644 %{SOURCE1} %{buildroot}/%{_sysconfdir}/%{name}.conf +install -m 0644 \ + %{SOURCE10} \ + %{SOURCE11} \ + %{SOURCE12} \ + %{SOURCE13} \ + %{SOURCE14} \ + %{SOURCE15} \ + %{SOURCE16} \ + %{SOURCE17} \ + %{buildroot}%{_unitdir} %check # Tests are only available with Vagrant # We just test that the binary works. %{buildroot}/%{_bindir}/%{name} version || exit 1 +%pre +%service_add_pre %{services} + +%post +%service_add_post %{services} + +%preun +%service_del_preun %{services} + +%postun +%service_del_postun %{services} + %files -%defattr(-,root,root) %doc README.md %license LICENSE -%config(noreplace) %attr (644,root,root) %{_sysconfdir}/%{name}.conf +%config(noreplace) %attr (640,root,postgres) %{_sysconfdir}/%{name}.conf # We still can do that as postgres user is system fixed %attr(-,postgres,postgres) %{_localstatedir}/log/%{name} %attr(-,postgres,postgres) %{_localstatedir}/lib/%{name} %attr(-,postgres,postgres) %{_localstatedir}/spool/%{name} %{_bindir}/%{name} +%{_unitdir}/pgbackrest-diff@.service +%{_unitdir}/pgbackrest-diff@.timer +%{_unitdir}/pgbackrest-full@.service +%{_unitdir}/pgbackrest-full@.timer +%{_unitdir}/pgbackrest-incr@.service +%{_unitdir}/pgbackrest-incr@.timer +%{_unitdir}/pgbackrest.service +%{_unitdir}/pgbackrest.target -%changelog +%changelog \ No newline at end of file diff --git a/pgbackrest.target b/pgbackrest.target new file mode 100644 index 0000000..8946ae4 --- /dev/null +++ b/pgbackrest.target @@ -0,0 +1,3 @@ +[Unit] +Description=Target to restart/stop all parts of pgbackrest +