File mysql-backupscript.spec of Package mysql-backupscript

# spec file for package mysql-backupscript
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
%if 0%{?suse_version} >= 1210
%bcond_without systemd
%bcond_with systemd

Name:           mysql-backupscript
Version:        2.0.2
Release:        0
Summary:        Simple mysql database backup
License:        BSD-3-Clause
Group:          System/Monitoring
Source1:        mysql-backupscript
Source2:        mysql-backup.sysconfig
Source3:        mysql-backup.logrotate
Source4:        README.SUSE
Source5:        LICENSE
Source6:        %{name}.timer
Source7:        %{name}.service
Requires:       logrotate
Requires:       mailx
Requires:       mysql-client
Requires:       net-tools
Recommends:     xz
Requires(pre):  %fillup_prereq
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch
%if %{with systemd}
BuildRequires: systemd-rpm-macros
Requires(pre): systemd
Requires:       cron

This package contains a simple mysql database backup script
running daily.

To restore, simply 'cd' into the backup directory of your
choise (configured in %{_sysconfdir}/sysconfig/mysql-backupscript),
bunzip2 the database file you want to restore and run:
  mysql < $dbfile
That's it. The script also copies your %{_sysconfdir}/my.cnf away, so
you have something at hand if you played too much with the
settings there ;-)

More information can be found in

install -m644 %{SOURCE5} .
install -m644 %{SOURCE4} .


install -Dm755 %{SOURCE1} %{buildroot}/%{_sbindir}/mysql-backupscript
%if %{with systemd}
install -Dm644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}.service
install -Dm644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}.timer
ln -s %{_sbindir}/%{name} %{buildroot}/%{_sbindir}/rc%{name}
mkdir -p %{buildroot}/%{_sysconfdir}/cron.daily
ln -s %{_sbindir}/%{name} %{buildroot}/%{_sysconfdir}/cron.daily/
install -Dm644 %{SOURCE2} %{buildroot}/%{_fillupdir}/sysconfig.mysql-backupscript
install -Dm644 %{SOURCE3} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name}

output=$(%buildroot/%{_sbindir}/%{name} -h 2>&1) || :
exit_code=$(echo $?)
if [ "$exit_code" != "$expected_exit_code" ]; then
    echo "ERROR: exit code is not as expected: $exit_code"
    exit 1

%if %{with systemd}
%service_add_pre %{name}.service %{name}.timer

%service_add_post %{name}.service %{name}.timer
# enable the timer if the package is installed for the first time
if [ ${1:-0} -eq 1 ]; then
    %{_bindir}/systemctl enable %{name}.timer
    %{_bindir}/systemctl start %{name}.timer
%{fillup_only %name}

%service_del_preun %{name}.service %{name}.timer

%service_del_postun %{name}.service %{name}.timer
%{fillup_only %{name}}

%doc README*
%if 0%{?suse_version} >= 1500
%license LICENSE
%if %{with systemd}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%if %{?suse_version} < 1230 &&  %{?suse_version} > 1140
%dir %{_fillupdir}