2.5. Backing Up and Recovering Data

GnuCash creates several types of files to help ensure that your data is not lost. If you look in the folder where your saved file resides, you may see other files generated by GnuCash with the following extensions: .gnucash, .log, .LCK, .LNK in the same directory as your primary data file. What each of these files does is presented below.

Note

The following sections are relevant only if you are saving your financial data in the XML format

      $ ls
      myfile.gnucash
      myfile.gnucash.20100414185747.gnucash
      myfile.gnucash.20100414223248.log
      myfile.gnucash.20100415114340.gnucash
      myfile.gnucash.20100415154508.log
      myfile.gnucash.20100415173322.gnucash
      myfile.gnucash.20100415194251.log
      myfile.gnucash.7f0982.12093.LNK
      myfile.gnucash.LCK
    

2.5.1. Backup file (.gnucash)

Each time you save your data file, a backup copy will also be saved with the extension .YYYYMMDDHHMMSS.gnucash. This backup file is a complete copy of your previous data file, and the filename format refers to the data file, year, month, day and time of the backup. For example, the filename myfile.gnucash.20100414185747.gnucash indicates this is a backup copy of the file myfile saved in the year 2010, April 14, at 6:57:47 p.m.

To restore an old backup file, simply open the .YYYYMMDDHHMMSS.gnucash file with the date to which you wish to return. Be sure to save this file under a different name.

Note

.YYYYMMDDHHMMSS.xac instead of the actual extension .YYYYMMDDHHMMSS.gnucash. So if you upgrade from the 2.2 series to the 2.4 series, you may end up with both .YYYYMMDDHHMMSS.xac and .YYYYMMDDHHMMSS.gnucash backup files in your directory.

2.5.2. Log file (.log)

Each time you open and edit a file in GnuCash, GnuCash creates a log file of changes you have made to your data file. The log file uses a similar naming format as the backup files: .YYYYMMDDHHMMSS.log. Log files are not a full backup of your data file - they simply record changes you have made to the data file in the current GnuCash session.

In case you exit GnuCash inadvertently, possibly due to a power outage or a system wide crash, it is possible to recover most of your work since the last time you saved your GnuCash file using this log file. This is the procedure:

  1. Open the last saved GnuCash file.

  2. Go to FileImportReplay GnuCash .log file and select the one .log file with the same date as the saved file you just opened. Make sure that you picked the right .log file, or you will possibly wreak havoc in your accounts.

Log replaying will recover any transaction affecting the balance entered since the last save, including those created from scheduled transactions and business features (invoices, bills, etc.).

Warning

Changes to the scheduled transactions, invoices or bills themselves are NOT recovered, and their transactions that were recovered may not be properly associated with them, and should thus be double-checked. Especially for business transactions, you may have to delete and re-create some of them. If you do not, although the balance will be correct, some reports may not.

2.5.3. Lock files (.LNK and .LCK)

You may occasionally see .LNK and .LCK files appear. These do not store any data, but they are created to prevent more than one user from opening the same file at the same time. These files are automatically created when you open the file, to lock it so no one else can access it. When you close your GnuCash session or open another file, GnuCash unlocks the first data file by deleting the .LCK and .LNK files.

If GnuCash crashes while you have a data file open, the .LCK and .LNK files are not deleted. The next time you try to open GnuCash, you will get a warning message that the file is locked. The warning message appears because the .LNK and .LCK files are still in your directory. It is safe to choose Yes to open the file, but you should delete the .LNK and .LCK files (using a terminal window or your file manager). Once those files are deleted, you will not get the warning message again unless GnuCash crashes.

2.5.4. File Management

So which files should you keep around? Keep your main data file, of course. It’s a good idea to keep some of the more recent .YYYYMMDDHHMMSS.gnucash backup files, but you can safely delete the .log files since they are not complete copies of your data.

Note

If you upgraded from a GnuCash version prior to 2.4, you may also have backup files in the old .xac format. For these files you can apply the same principle described above for .YYYYMMDDHHMMSS.gnucash backup files.

You should also delete any .LCK and .LNK files that you see after closing GnuCash. If you decide to back up your data file to another disk manually, it’s enough to back up the main data file - not the .YYYYMMDDHHMMSS.gnucash backup files.

Note

By default GnuCash will automatically delete any .log and .YYYYMMDDHHMMSS.gnucash backup files that are older than 30 days. You can change this behavior in the GnuCash preferences in the General tab under EditPreferences ( GnuCashPreferences on macOS).