Difference between revisions of "Backup"

From GnuCash
Jump to: navigation, search
(note on auto-saving)
(Backup - moving FAQ questions not directly related to backup back to FAQ page)
Line 1: Line 1:
 
== Introduction ==  
 
== Introduction ==  
  
How one creates a backup of GnuCash data depends mostly on the type of backend used to store the book information.
+
Backing up your GnuCash data is important to protect and secure your financial data from potential equipment failure or data corruption.  
  
'''XML''' backends, the default GnuCash data store, include an automatic mechanism which will create a dated copy of your book every time the changes are saved. It will also create .log files which contain changes made in between the saves.
+
GnuCash does not directly provide back up services for this type of failure. Recovering data in the event of equipment failure depends on having a robust backup process that includes offsite storage of up-to-date copies of your data. You are strongly advised to implement such processes.
  
With '''SQL''' backends, saving of changes is atomic, meaning either they are all saved to the database or none is. GnuCash saves changes to sql data stores automatically, unlike xml backend, which requires explicit Save action either by clicking the Save button or using Autosave functionality in the preferences.
+
==GnuCash Data Files==
For this reason, replaying the .log files would be unnecessary. Enough precaution would be to regularly back up the database file.
 
  
'''SQLite''' backend uses SQLite database file as the data store for the book. This means it is fairly simple to back up this file by manually creating a copy or utilizing one of many file backup tools available.
+
Determining what are the GnuCash data files depends on the type of backend used to store the book information.
Note that, even though there is no automatic backup file generated when using SQLite backend, GnuCash will still generate the .log files with changes.
 
While it might possible to replay the .log files on top of an sql book, this is not officially supported. One option, in case of data loss, might be to convert the sqlite book to xml and replay the transactions log on top of that. More info in the related [https://bugzilla.gnome.org/show_bug.cgi?id=795393 bug].
 
  
Other '''SQL'''-type backends (PostgreSQL, MariaDB/MySQL) are utilizing database servers and would be best backed-up using the related server's backup mechanism.
+
* If you're using the XML (default) backend, GnuCash makes local backups for you every time it saves your file. You must save your file (by clicking the Save button or using Autosave functionality in the preferences). It does this by renaming the previous version of the file with a date-time-stamp and a new .gnucash suffix. For example, if your data file is named MyAccounts.gnucash, one of the backups might be named MyAccounts.gnucash.20140131150812.gnucash.
  
== FAQ ==
+
* With '''SQL''' backends, GnuCash saves changes to sql data stores automatically as you go. For this reason, there are no backup files for the SQL. Even though there are no automatic backup files generated when using SQLite backend, GnuCash will still generate .log files with changes. While it might possible to replay .log files on top of an sql book, this is not officially supported. One option, in case of data loss, would be to convert the sqlite book to xml and replay the transactions log on top of that and then re-save the file in SQLite. More info in the related [https://bugzilla.gnome.org/show_bug.cgi?id=795393 bug].
  
Below are related FAQ entries.
 
 
===='''Q:''' How do I backup my data?====
 
'''A:'''It depends.
 
:* If you're using the XML (default) backend, GnuCash makes local backups for you every time it saves your file. It does this by renaming the previous version of the file with a date-time-stamp and a new .gnucash suffix. For example, if your data file is named MyAccounts.gnucash, one of the backups might be named MyAccounts.gnucash.20140131150812.gnucash.
 
 
:* If you're using the SQLite3 backend you should use a timed backup program to copy your account file in some way.
 
:* If you're using the SQLite3 backend you should use a timed backup program to copy your account file in some way.
 
:* If you're using either the MySQL or Postgresql backend, you should perform backups on the database in accordance with the recommended best practices appropriate to the server. We're not competent to advise you about this beyond recommending that you make backups.
 
:* If you're using either the MySQL or Postgresql backend, you should perform backups on the database in accordance with the recommended best practices appropriate to the server. We're not competent to advise you about this beyond recommending that you make backups.
:* We strongly recommend that whatever backup plan you use includes a provision for offsite backups. A good option is one of the many internet storage facilities like [https://www.dropbox.com/ DropBox], [https://drive.google.com/ Google Drive], or [http://www.carbonite.com/ Carbonite]. Those are just popular examples; there are dozens of such services, and we can make no recommendation of one over another.
 
 
:: There is a free 3rd party tool for creating GnuCash backups called BackupGnuCash. See http://wiki.gnucash.org/wiki/Published_tools.
 
:* Restoring is simply a matter of removing the defective MyAccounts.gnucash and renaming one of the backup files to that, then starting Gnucash or using File>MyAccounts or File>Open and selecting MyAccounts.gnucash from the File Chooser.
 
:* To restore from an off-disk backup, just copy MyAccounts.gnucash back into the directory where the original is.
 
 
===='''Q:''' What are all these .gnucash and .log files filling up my directory?====
 
 
:'''A:''' These are backup [[File|data files]] (".gnucash"; it was ".xac" in versions before 2.4) and log files (".log") that GnuCash creates to prevent data loss.  Gnucash will remove them after a configurable amount of time (Preferences/General/"Days to retain log files").  In the normal case when your data file is ok and you don't need old versions of the file, you can remove these files safely.
 
 
:You should notice that the backup and log files have a format of <name>.YYYYMMDDHHMMSS.gnucash (or .log).  These are backup (and log) files from your data file, <name>.
 
 
:Note that .log files are to be used only if you are using an XML backend for the book. With SQL storage, it is not recommended to replay the .log files. The data is always saved to the data store and the possibility of data loss is minimal in that case.
 
:This topic is covered more broadly in [https://www.gnucash.org/docs/v3/C/gnucash-guide/basics-backup1.html Backing Up and Recovering Data] section of the User Guide.
 
 
===='''Q:''' Why is my file name getting longer and longer?====
 
 
:'''A:''' GnuCash creates a backup file by taking the current data file and adding the date/time to the end (YYYYMMDDHHMMSS.gnucash). Older versions up to 2.3.x still used the form YYYYMMDDHHMMSS.xac - from GnuCash's ancestor XAccountant. So if you're using a file named "Foo.gnucash", then you'll get backups of the form:
 
 
:  Foo.gnucash.20100719100214.gnucash
 
 
:Now assume that instead of opening "Foo.gnucash" you open one of these backup files, you make changes to it and then save the file.
 
:For starters, this means you've just over-written the original backup file which is always a bad idea. Backups should never be changed.
 
:Secondly since you saved changes, GnuCash will create a backup file based the file you just changed using the same naming system: it adds a date/time extension. Since the file you saved already had such an extension, you end up with a backup file named:
 
 
:  Foo.gnucash.20100719100214.gnucash.20100719112352.gnucash
 
 
:Repeating this process will add to the file name until it exceeds the operating system limits.
 
 
:The fix:
 
  
:1) Don't open a backup file
+
As noted above, it is strongly recommended that whatever backup plan you use includes a provision for offsite backups. A good option is one of the many cloud storage services like [https://www.dropbox.com/ DropBox], [https://drive.google.com/ Google Drive], or [http://www.carbonite.com/ Carbonite]. Those are just popular examples; there are dozens of such services, and we can make no recommendation of one over another.
:1a) If you DO open a backup file, '''never''' simply save it out again, instead use Save As to give it a new name.
 
:2) Make sure you're always using your base data file
 
:3) If your base data file for some reason is bad, and you need to recover from a previous backup file, copy the backup file over your bad base file, for example:
 
  
:   cp Foo.gnucash.20100719100214.gnucash.20100719112352.gnucash Foo.gnucash
+
:There is a free 3rd party tool for creating GnuCash backups called BackupGnuCash. See [[Published_tools]].
  
:and then File -> Open the new file, Foo.gnucash.
+
==Related Files==
  
===='''Q:''' Gnucash crashed and lost a bunch of my edits. How do I recover them?====
+
Of course, you should save your actual data files, although it is up to you whether you save the backup and log files (''.gnucash'' or ''.xac'', ''.log''). See [[#GnuCash data files]], above, for more on the subject.
  
:'''A:''' First, read the previous two FAQs about backup and logfiles.
+
In addition to the actual data file, however, there are a number of files that store your preferences, user interface settings, and saved reports. It is advisable to back these resources up as well.
  
:The first thing to check is that you are, in fact, opening the right file. Look up in the title bar: If it has a long string of numbers starting e.g. 20111011 (2011-10-11, i.e., 11 October 2011) then you've opened the wrong file. If you haven't done this too many times, the right one should still be in the recent list in the File menu. Open it and make sure that you really have lost work.
+
[[Configuration Locations]] identifies the OS-dependent locations of all the different files, as well as their names.
  
:If you're sure that you got the right file and that your work is still missing, look at the log files for that data file -- and for any backup files you might have entered data into (Those will have logfiles with names that look like filename.timestamp.gnucash.timestamp.log). Quicklook works on log files, so you can browse the log files in Finder. Find the earliest one for which data does ''not'' appear in your data file and select <tt>File>Import>Replay Gnucash .log File</tt>, then select that log file. Repeat for every subsequent log file.
+
Preferences you need also to save
 +
# Normal '''configuration''' data:
 +
::* Gnucash 3.0 and newer: The contents of [[Configuration Locations#GNC_DATA_HOME|GNC_DATA_HOME]] and [[Configuration Locations#GNC_CONFIG_HOME|GNC_CONFIG_HOME]].
 +
::* Gnucash 2.x and older:
 +
:::;Linux and Windows: '''[[Configuration Locations#HOME|HOME]]\.gnucash''' - most of your preferences, adjusted report settings, column withs, window positions, ...
 +
:::;MacOS: '''$HOME/Library/Application Support/Gnucash'''
  
:Click the save button.
+
# '''Preferences''' from <tt>Edit->Preferences</tt> (like [[#Q: I have deleted a gnucash file from my computer. How can I remove that file from the File menu's short list (MRU) as well ?|history]], sign reversals, auto save interval,...) are stored using GSettings (for gnucash 2.6 and newer) or GConf (for gnucash 2.4 and older).
 +
#*'''GSettings''' based settings ('''GnuCash 2.6''' and newer) - How to back these up depends on your platform:
 +
#:*'''Linux and similar:''' GSettings uses dconf as backend. You can use the '''dconf''' tool to dump all the preferences:
 +
#::<code>dconf dump /org/gnucash/</code>
 +
:#:*'''Windows:''' Gsettings uses the Windows registry as backend. You can make a backup of the ''HKEY_CURRENT_USER/Software/GSettings/org/gnucash/'' registry key using the <code>regedit</code> command ('''Registry Editor''').
 +
:#:*'''MacOS:''' GSettings uses the system's native defaults. You can use the '''defaults''' tool to dump all the preferences:
 +
:#::<code>defaults read --app Gnucash</code>
 +
:#* '''GConf''' based settings ('''GnuCash 2.4''' and older):
 +
:#:The GConf settings are stored in [[Configuration Locations#HOME|HOME]]/.gconf/apps/gnucash/
 +
:# For ''Gnucash 3.0 and up'', if you made changes to the '''Gtk configuration''' (settings.ini or gtk.css) or have installed custom '''themes''' and/or icon themes you may want to back up the contents of the following directories as well: [[Configuration Locations#GTK_DATA_HOME|GTK_DATA_HOME]], [[Configuration Locations#GTK_CONFIG_HOME|GTK_CONFIG_HOME]], [[Configuration Locations#USER_CONFIG_HOME|USER_CONFIG_HOME]]/themes and [[Configuration Locations#USER_CONFIG_HOME|USER_CONFIG_HOME]]/icons. [[GTK3]] has more info on when these directories are used.
 +
:
  
:Go back to work.
+
# Lastly if you are using [[AqBanking]] online banking
 +
::*'''Linux and similar, and MacOS:'''
 +
:::'''[[Configuration Locations#HOME|HOME]]/.[aq]banking''' holds your online banking settings. In older versions it was named ''.banking'' but ''.aqbanking'' is the current name.
 +
::*'''Windows:'''
 +
:::'''[[Configuration Locations#HOME|HOME]]/aqbanking'''
  
:'''Warning:'' The log file will not replay business actions.''''' So if you posted invoices or processed payments or did anything else with the business functions, replaying the log '''''will destroy your data!'''''  Do ''not'' replay a log that has transactions from business feature operations or internal data structures will be completely messed up and you will have lots of trouble cleaning up later.
+
==Restoring==
  
:If you did lose business feature work the only thing you can do is redo the work by hand and then make sure you click save.
+
Restoring a data file is simply a matter of removing the defective file and renaming one of the backup files to that, then starting Gnucash or using File>Open and selecting the file from the File Chooser.
  
:Save early, save often.
+
To restore from an offsite backup, just copy the remote file back into the directory where the original is.

Revision as of 06:29, 19 October 2018

Introduction

Backing up your GnuCash data is important to protect and secure your financial data from potential equipment failure or data corruption.

GnuCash does not directly provide back up services for this type of failure. Recovering data in the event of equipment failure depends on having a robust backup process that includes offsite storage of up-to-date copies of your data. You are strongly advised to implement such processes.

GnuCash Data Files

Determining what are the GnuCash data files depends on the type of backend used to store the book information.

  • If you're using the XML (default) backend, GnuCash makes local backups for you every time it saves your file. You must save your file (by clicking the Save button or using Autosave functionality in the preferences). It does this by renaming the previous version of the file with a date-time-stamp and a new .gnucash suffix. For example, if your data file is named MyAccounts.gnucash, one of the backups might be named MyAccounts.gnucash.20140131150812.gnucash.
  • With SQL backends, GnuCash saves changes to sql data stores automatically as you go. For this reason, there are no backup files for the SQL. Even though there are no automatic backup files generated when using SQLite backend, GnuCash will still generate .log files with changes. While it might possible to replay .log files on top of an sql book, this is not officially supported. One option, in case of data loss, would be to convert the sqlite book to xml and replay the transactions log on top of that and then re-save the file in SQLite. More info in the related bug.
  • If you're using the SQLite3 backend you should use a timed backup program to copy your account file in some way.
  • If you're using either the MySQL or Postgresql backend, you should perform backups on the database in accordance with the recommended best practices appropriate to the server. We're not competent to advise you about this beyond recommending that you make backups.

As noted above, it is strongly recommended that whatever backup plan you use includes a provision for offsite backups. A good option is one of the many cloud storage services like DropBox, Google Drive, or Carbonite. Those are just popular examples; there are dozens of such services, and we can make no recommendation of one over another.

There is a free 3rd party tool for creating GnuCash backups called BackupGnuCash. See Published_tools.

Related Files

Of course, you should save your actual data files, although it is up to you whether you save the backup and log files (.gnucash or .xac, .log). See #GnuCash data files, above, for more on the subject.

In addition to the actual data file, however, there are a number of files that store your preferences, user interface settings, and saved reports. It is advisable to back these resources up as well.

Configuration Locations identifies the OS-dependent locations of all the different files, as well as their names.

Preferences you need also to save

  1. Normal configuration data:
Linux and Windows
HOME\.gnucash - most of your preferences, adjusted report settings, column withs, window positions, ...
MacOS
$HOME/Library/Application Support/Gnucash
  1. Preferences from Edit->Preferences (like history, sign reversals, auto save interval,...) are stored using GSettings (for gnucash 2.6 and newer) or GConf (for gnucash 2.4 and older).
    • GSettings based settings (GnuCash 2.6 and newer) - How to back these up depends on your platform:
    • Linux and similar: GSettings uses dconf as backend. You can use the dconf tool to dump all the preferences:
    dconf dump /org/gnucash/
    • Windows: Gsettings uses the Windows registry as backend. You can make a backup of the HKEY_CURRENT_USER/Software/GSettings/org/gnucash/ registry key using the regedit command (Registry Editor).
    • MacOS: GSettings uses the system's native defaults. You can use the defaults tool to dump all the preferences:
    defaults read --app Gnucash
    • GConf based settings (GnuCash 2.4 and older):
    The GConf settings are stored in HOME/.gconf/apps/gnucash/
  1. For Gnucash 3.0 and up, if you made changes to the Gtk configuration (settings.ini or gtk.css) or have installed custom themes and/or icon themes you may want to back up the contents of the following directories as well: GTK_DATA_HOME, GTK_CONFIG_HOME, USER_CONFIG_HOME/themes and USER_CONFIG_HOME/icons. GTK3 has more info on when these directories are used.
  1. Lastly if you are using AqBanking online banking
  • Linux and similar, and MacOS:
HOME/.[aq]banking holds your online banking settings. In older versions it was named .banking but .aqbanking is the current name.
  • Windows:
HOME/aqbanking

Restoring

Restoring a data file is simply a matter of removing the defective file and renaming one of the backup files to that, then starting Gnucash or using File>Open and selecting the file from the File Chooser.

To restore from an offsite backup, just copy the remote file back into the directory where the original is.