KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Integrating Journals and Logs into Restored Backups
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: May 28, 2024

An important failover feature of 4D is the backup feature. 4D provides a backup feature that can be scheduled to perform a backup of the current state of the database at the time. By default, when a backup is performed, the data and structure are backed up. It is important for the data to be backed up as this is the most critical portion of a database.

Details

When a backup is performed a .4BK and a .4BL is generated. The .4BK is the 4D BacKup file which can be thought of as a compression of the backed-up files. With the default settings, this would be like a zip file containing the structure and data file.

The .4BL is an important feature of 4D that prevents as much data loss as possible. The .4BL is the 4D Backup Log which is a copy of the journal file at the time of the backup. When the backup succeeds, a new journal file is created. The journal file contains a log of all of the database operations performed such as new records, updates, and deletes.

When the files are generated, the .4BK will be numbered based on the count of backups in the current backup chain, while the .4BK will be numbered -1 of the current count. That is because the current backup already has the data in the data file, while the .4BL contains the log of operations performed since the last backup. It is important that the chain is maintained, if a new chain is started the logs may not integrate with restored backups from a different chain.

When the backup system is used and an error occurs that damages the database somehow, the suggested first step for recovery is always to restore from the backup. When a backup is restored, an option is available to integrate logs and journals.

The integration of logs and journals allows the process to reproduce all of the logged operations to replicate any missing actions since the backup. This means that if 2 days have passed since the last backup, all of these operations should have been logged in the journal file. If the backup is restored, and the journal file is integrated, all of the operations logged in the journal file will be replicated on the data file restoring most, if not all, of the actions in the last two days.

If the damage has been ongoing and unnoticed for a while, it is possible to restore from an even older backup, and then integrate (in chronological order) the .4BL and journal files. For example, if a corruption occurred sometime 2 backups ago, a restore can be performed on the 3rd newest backup, and integrating the backup logs from the backup logs (.4BL) and journal file of the two backups since.

Restore and Integration Steps

Below are the steps to perform a restore and integration:
1) The first step is to open 4D/4D Server's Maintenance Security Center (MSC), this can be done so with any structure (the current database structure, a restored structure, or a brand new empty/dummy database).

2) The next step is to go to the "Restore" section of the MSC.

3) Next click on "Browse..." and specify the specific backup file (.4BK) to restore.

4) Enable (Check) the "Integrate one or more log file(s) after restore" option.

5) Specify the "Destination folder of the restored files" if needed

6) Click on "Restore" to start the process

7) When the restore completes, an Alert dialog will appear and ask if a log/journal file should be integrated. Click "Yes" and select the oldest log after the backup is restored.

8) An Alert will display with the number of operations integrated into the data file and ask if another log/journal file should be integrated. Click "Yes" and repeat the process for each additional .4BL and journal file needed or click "No" when everything has been integrated.

Example

Below is an example.
Starting with a new empty database named SampleDB which has not performed any backups yet.
Three(3) records are added: A, B, and C. These operations are logged in the current journal file.
The first backup is performed by generating:
- SampleDB[0000].4BL <- A copy of the journal file
- SampleDB[0001].4BK <- A compression of the data file and structure file (default settings)
A new empty journal file is created after the backup succeeds.

Three new records are added (D, E, and F). These operations are logged in the new current journal file.
A backup is performed generating:
- SampleDB[0001].4BL
- SampleDB[0002].4BK

Once again another three records are added afterward (G, H, and I) and a backup is performed generating:
- SampleDB[0002].4BL
- SampleDB[0003].4BK

Finally, another three records are added (J, K, and L) resulting in 12 records total.

At this point, the current data file has 12 records. With the backup files and the current journal file, any of the backups can be used to restore a data file with all 12 records.
Below is what each of the items essentially contains from a records perspective
- SampleDB[0000].4BL <- (Logged Operations of creating Records A, B, and C)
- SampleDB[0001].4BK <- (Datafile containing Records A, B, and C)
- SampleDB[0001].4BL <- (Logged Operations of creating Records D, E, and F)
- SampleDB[0002].4BK <- (Datafile containing Records A, B, C, D, E, and F)
- SampleDB[0002].4BL <- (Logged Operations of creating Records G, H, and I)
- SampleDB[0003].4BK <- (Datafile containing Records A, B, C, D, E, F, G, H, and I)
- Current .journal file <- (Logged Operations of creating Records J, K, and L)

Typically, for the best speed the process would be to restore the latest backup, SampleDB[0003].4BK, this will restore a datafile with Records A, B, C, D, E, F, G, H, and I (9 records). Then to restore the missing records since the backup, integrate the .journal file which will perform the operations to create records J, K, and L resulting in a data file with the 12 records.

Hypothetically, if a corruption occurred and went unnoticed sometime after the first backup and restoring SampleDB[0002].4BK and SampleDB[0003].4BK results in a corrupted database, SampleDB[0001].4BK can be restored.
To get the 12 records in this scenario first restore SampleDB[0001].4BK which will generate a datafile with the first 3 records (A, B, and C). Then when integrating the logs start with integrating the matching numbered log, SampleDB[0001].4BL. This will integrate the operations by adding in records D, E, and F. Then integrate the next log SampleDB[0001].4BL, adding in records G, H, and I. Finally, integrate the journal adding in records J, K, and L. This will result in the data being restored from the first backup with all 12 records by integrating each of the logs and journals created after.