2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenLdapのバックアップをslapcat で行う時のコマンドオプションは具体的にどれがいいの?

Last updated at Posted at 2020-11-04

OpenLdapのバックアップをslapcatでとろうとしていてネット検索しましたが、異なるオプションの記載があり、どれがいいのか迷ったので調査しました。

結論

LDAPアカウントのバックアップ

# slapcat -n 2 -l ldap-YYYYMMDD.ldif

設定バックアップ

# slapcat -b cn=config -l ldap-config-YYYYMMDD.ldif

slapcatオプション

# man slapcat

-l ldif-file
        Write LDIF to specified file instead of standard output.
		標準出力ではなく、指定されたファイルにLDIFを書き込みます。

-b suffix
      Use the specified suffix to determine which database to generate output for.  The -b cannot be used in conjunction with the -n option.
      指定されたサフィックスを使用して、出力を生成するデータベースを決定します。 -bを-nオプションと組み合わせて使用することはできません。

-n dbnum
      Generate output for the dbnum-th database listed in the configuration file. The config database slapd-config(5), is always the first database, so use -n 0 to select it.
	  構成ファイルにリストされているdbnum-thデータベースの出力を生成します。 構成データベースslapd-config(5)は常に最初のデータベースであるため、-n0を使用して選択します。

      The -n cannot be used in conjunction with the -b option.
      -nを-bオプションと組み合わせて使用することはできません。

詳細

【slapcat/slapadd】の使い方, オプション~OpenLDAPのBackup/Resotreや移行, cn=config, cn=monitor, エラー~ | SEの道標

一番参考になりました。

OpenLDAPの設定のバックアップ

[root@localhost ~]# slapcat -b cn=config -l ldap-config-YYYYMMDD.ldif

もしくは

[root@localhost ~]# slapcat -n 0 -l ldap-config-YYYYMMDD.ldif

-n はデータベース番号を指定するオプション、-b はLDAPツリーのDNを指定するオプションです。-n と -b は同時には使えません。config のデータベース番号は0です。

LDAPアカウントのバックアップ
LDAPアカウントのバックアップは以下のコマンドを使います。

[root@localhost ~]# slapcat -l ldap-YYYYMMDD.ldif
これでも正常にバックアップはできますが、必ず以下のエラーが出力されます。

The first database does not allow slapcat; using the first available one (2).

(中略)

このエラーを出力しないようにLDAPアカウントのバックアップを取得するためには以下のコマンドを使います。

[root@localhost ~]# slapcat -n 2 -l ldap-YYYYMMDD.ldif

つまり2番目のデータベースを取得するわけです。(エラーにある最後の(2).は2番目のデータベースを使え、という意味です。)

なお、モニターデータベースは SNMP MIB データベースのような使われ方をするもので、現在のセッション数等の統計情報を司るものですが、slapcat が許可されておらず、以下コマンドを実行しようとするとその次のエラーが出ます。

[root@localhost ~]# slapcat -n 1
slapcat: database doesn't support necessary operations.

slapcat は使えませんが、ldapsearch を使ってモニター情報の取得ができます。

[root@localhost ~]# ldapsearch -x -b cn=monitor -s sub +

もしもに備えるバックアップ、リストア(1) (2/2):OpenLDAPによるディレクトリサーバ運用(1) - @IT

# ./sbin/slapcat -l /path/to/backup.ldif    ←論理データの抽出

このコマンドだと、The first database does not allow slapcat; using the first available one (2).エラーが出る。(けどバックアップはとれる)

CentOS7でOpenldap構築 - 5.バックアップ、リストアテスト - Qiita

データベースバックアップ
slapcat -n 2 > ldap_date "+%Y%m%d%H%M".ldif

設定バックアップ
slapcat -b cn=config > ldapconfig_date "+%Y%m%d%H%M".ldif

標準出力でファイル出力するか -l で出力するかの違い。
厳密には違うんだろうけど、どちらでも大丈夫そう。
オプションあるため、-l で出力する方式を採用。

ubuntu 14.04でldapのバックアップ・リストア - Qiita

slapcatを使ってldif形式でバックアップ

# slapcat > ldap-bak.ldif
# slapcat -b cn=config > ldap-config-bak.ldif

ubuntu でも同様のコマンドでいけるらしい。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?