4.3. Backing up and Restoring Data
Databases can be backed up and restored using the Directory Server Console or a command-line script.
Do not stop the server during a backup or restore operation.
The following procedures describe backing up all of the databases in the directory using the Directory Server Console and from the command-line.
These backup methods cannot be used to back up the data contained by databases on a remote server that are chained using database links.
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:
Select the Tasks tab.
Click Back Up Directory Server.
The Backup Directory dialog box opens.
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-. [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).
instance_name/bak
Click OK to create the backup.
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, refer to Section 4.3.1.2, “Backing up All Databases from the Command-Line”.
To back up the directory from the command-line using the db2bak script, do the following:
Open the Directory Server instance directory:
cd /usr/lib/dirsrv/slapd-instance_name
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-. [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).
instance_name/bak
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- directory.
instance_name
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- directory before the directory writes the modifications to the instance_namedse.ldif file.
The following procedures describe restoring all of the databases in the directory using the Directory Server Console and from the command-line.
While restoring databases, the server must be running. However, the databases will be unavailable for processing operations during the restore.
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.
Restoring databases overwrites any existing database files.
To restore databases from a previously created backup, do the following:
In the Directory Server Console, select the Tasks tab.
Click Restore Directory Server.
The Restore Directory dialog box is displayed.
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-backup_directory. [3]backup_directory is the directory of the most recent backup, in the form serverID-YYYY_MM_DD_hhmmss.
instance_name/bak/
Click OK.
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.
To restore the directory from the command-line, do the following:
If the Directory Server is running, stop it:[4]
service dirsrv stop instance
Open the Directory Server instance directory:
cd /usr/lib/dirsrv/slapd-instance_name
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.
To restore the directory from the command-line, do the following while the server is running:
Open the Directory Server instance directory:
cd /usr/lib/dirsrv/slapd-instance_name
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. |
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:
Stop the Directory Server if it is running.[4]
service dirsrv stop instance
Restore the backend from the /var/lib/dirsrv/slapd- archives with the instance_name/bakbak2db script, using the -n parameter to specify the database name. For example:
bak2db /var/lib/dirsrv/slapd-instance_name/bak/backup_file-n userRoot
Restart the Directory Server.
service dirsrv start instance
If the Directory Server fails to start, remove the database transaction log files in /var/lib/dirsrv/slapd-, then retry starting the server.
instance_name/db/log.###
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.
The directory creates two backup copies of the dse.ldif file in the /etc/dirsrv/slapd- directory. The instance_namedse.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:
Stop the server.[4]
service dirsrv stop instance
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.
Restart the server.
service dirsrv restart instance