Product SiteDocumentation Site

4.3. Backing up and Restoring Data

Databases can be backed up and restored using the Directory Server Console or a command-line script.

WARNING

Do not stop the server during a backup or restore operation.

4.3.1. Backing up All Databases

The following procedures describe backing up all of the databases in the directory using the Directory Server Console and from the command-line.

NOTE

These backup methods cannot be used to back up the data contained by databases on a remote server that are chained using database links.

4.3.1.1. Backing up All Databases from the Server Console

When backing up databases from the Directory Server Console, the server copies all of the database contents and associated index files to a backup location. A backup can be performed while the server is running.
To back up databases from the Directory Server Console, do the following:
  1. Select the Tasks tab.
  2. Click Back Up Directory Server.
    The Backup Directory dialog box opens.
  3. Enter the full path of the directory to store the backup file in the Directory text box, or click Use default, and the server provides a name for the backup directory.
    If the Console is running on the same machine as the directory, click Browse to select a local directory.
    With the default location, the backup files are placed in /var/lib/dirsrv/slapd-instance_name/bak. [3] By default, the backup directory name contains the name of the server instance and the time and date the backup was created (instance_name-YYYY_MM_DD_hhmmss).
  4. Click OK to create the backup.

4.3.1.2. Backing up All Databases from the Command Line

Databases can be backed up from the command-line using the db2bak command-line script. This script works when the server is running or when the server is stopped.
Configuration information cannot be backed up using this backup method. For information on backing up the configuration information, see Section 4.3.2, “Backing up the dse.ldif Configuration File”.
To back up the directory from the command-line using the db2bak script, do the following:
  1. Open the Directory Server instance directory:
    cd /usr/lib/dirsrv/slapd-instance_name
    
  2. Run the db2bak command-line script.
    db2bak /var/lib/dirsrv/slapd-instance_name/bak/instance_name-2007_04_30_16_27_56
    
For more information about using this script, see the Directory Server Configuration, Command, and File Reference.
The backup directory where the server saves the backed up databases can be specified with the script. If a directory is not specified, the backup file is stored in /var/lib/dirsrv/slapd-instance_name/bak. [3] By default, the backup directory is named with the Directory Server instance name and the date of the backup (serverID-YYYY_MM_DD_hhmmss).

4.3.2. Backing up the dse.ldif Configuration File

Directory Server automatically backs up the dse.ldif configuration file. When the Directory Server is started, the directory creates a backup of the dse.ldif file automatically in a file named dse.ldif.startOK in the /etc/dirsrv/slapd-instance_name directory.
When the dse.ldif file is modified, the file is first backed up to a file called dse.ldif.bak in the /etc/dirsrv/slapd-instance_name directory before the directory writes the modifications to the dse.ldif file.

4.3.3. Restoring All Databases

The following procedures describe restoring all of the databases in the directory using the Directory Server Console and from the command-line.

NOTE

While restoring databases, the server must be running. However, the databases will be unavailable for processing operations during the restore.

4.3.3.1. Restoring All Databases from the Console

If the databases become corrupted, restore data from a previously generated backup using the Directory Server Console. This process consists of stopping the server and then copying the databases and associated index files from the backup location to the database directory.

WARNING

Restoring databases overwrites any existing database files.
To restore databases from a previously created backup, do the following:
  1. In the Directory Server Console, select the Tasks tab.
  2. Click Restore Directory Server.
    The Restore Directory dialog box is displayed.
  3. Select the backup from the Available Backups list, or enter the full path to a valid backup in the Directory text box.
    The Available Backups list shows all backups located in the default directory, /var/lib/dirsrv/slapd-instance_name/bak/backup_directory. [3]backup_directory is the directory of the most recent backup, in the form serverID-YYYY_MM_DD_hhmmss.
  4. Click OK.

4.3.3.2. Restoring Your Database from the Command-Line

Restore databases from the command-line by using the following scripts:
  • Using the bak2db command-line script. This script requires the server to be shut down.
  • Using the bak2db.pl Perl script. This script works while the server is running.
4.3.3.2.1. Using the bak2db Command-Line Script
To restore the directory from the command-line, do the following:
  1. If the Directory Server is running, stop it:[4]
    service dirsrv stop instance
    
  2. Open the Directory Server instance directory:
    cd /usr/lib/dirsrv/slapd-instance_name
    
  3. Run the bak2db command-line script. The bak2db script requires the full path and name of the input file.
    bak2db /var/lib/dirsrv/slapd-instance_name/bak/instance_name-2007_04_30_11_48_30
    
    For more information about using this script, see the Directory Server Configuration, Command, and File Reference.
4.3.3.2.2. Using bak2db.pl Perl Script
To restore the directory from the command-line, do the following while the server is running:
  1. Open the Directory Server instance directory:
    cd /usr/lib/dirsrv/slapd-instance_name
    
  2. Run the bak2db.pl Perl script.
    bak2db.pl -D "cn=Directory Manager" -w secret  
        -a /var/lib/dirsrv/slapd-instance_name/bak/instance_name-2007_04_30_11_48_30
    
    For more information on using this Perl script, see the Directory Server Configuration, Command, and File Reference.
Option Description
-a Defines the full path and name of the input file.
-D Specifies the DN of the administrative user.
-w Specifies the password of the administrative user.

4.3.4. Restoring a Single Database

It is possible to restore a single database through the command-line, but not in the Directory Server Console. To restore a single database, do the following:
  1. Stop the Directory Server if it is running.[4]
    service dirsrv stop instance
    
  2. Restore the backend from the /var/lib/dirsrv/slapd-instance_name/bak archives with the bak2db script, using the -n parameter to specify the database name. For example:
    bak2db /var/lib/dirsrv/slapd-instance_name/bak/backup_file -n userRoot
    
  3. Restart the Directory Server.
    service dirsrv start instance
    

    NOTE

    If the Directory Server fails to start, remove the database transaction log files in /var/lib/dirsrv/slapd-instance_name/db/log.###, then retry starting the server.

4.3.5. Restoring Databases That Include Replicated Entries

If a database that supplies entries to other servers is restored, then you must reinitialize all of the servers that receive updates from the restored database (for example, consumer servers, hub servers, and, in multi-master replication environments, other supplier servers). The changelog associated with the restored database will be erased during the restore operation. A message will be logged to the supplier servers' log files indicating that reinitialization is required. If a database containing data received from a supplier server is restored, then one of two situations can occur:
  • Changelog entries have not yet expired on the supplier server.
    If the supplier's changelog has not expired since the database backup was taken, then restore the local consumer and continue with normal operations. This situation occurs only if the backup was taken within a period of time that is shorter than the value set for the maximum changelog age attribute, nsslapd-changelogmaxage, in the cn=changelog5,cn=config entry. For more information about this option, see the Directory Server Configuration, Command, and File Reference.
    Directory Server automatically detects the compatibility between the replica and its changelog. If a mismatch is detected, the server removes the old changelog file and creates a new, empty one.
  • Changelog entries have expired on the supplier server since the time of the local backup.
    If changelog entries have expired, reinitialize the consumer. For more information on reinitializing consumers, refer to Section 8.10, “Initializing Consumers”.
For information on managing replication, see Chapter 8, Managing Replication.

4.3.6. Restoring the dse.ldif Configuration File

The directory creates two backup copies of the dse.ldif file in the /etc/dirsrv/slapd-instance_name directory. The dse.ldif.startOK file records a copy of the dse.ldif file at server start up. The dse.ldif.bak file contains a backup of the most recent changes to the dse.ldif file. Use the version with the most recent changes to restore the directory.
To restore the dse.ldif configuration file, do the following:
  1. Stop the server.[4]
    service dirsrv stop instance
    
  2. Restore the database as outlined in Section 4.3.4, “Restoring a Single Database” to copy the backup copy of the dse.ldif file into the directory.
  3. Restart the server.
    service dirsrv restart instance