{"id":433,"date":"2013-04-29T16:19:42","date_gmt":"2013-04-29T19:19:42","guid":{"rendered":"http:\/\/www.viazap.com.br\/?p=433"},"modified":"2013-04-29T16:19:42","modified_gmt":"2013-04-29T19:19:42","slug":"gbak-firebird-backup-and-restore","status":"publish","type":"post","link":"https:\/\/blog.clusterweb.com.br\/?p=433","title":{"rendered":"GBAK &#8211; Firebird Backup and Restore"},"content":{"rendered":"<p>GBAK is Firebird&#8217;s command line tool for online backup and restore of a complete database.<\/p>\n<p>GBAK is able to perform a backup while the database is running. There is no need to shut down the database during a GBAK backup. GBAK will create a consistent snapshot of the database at the time it starts running. You will, however, notice a perfomance degradation during the backup, so it is a good idea to backup at night. As GBAK visits all pages of the database, so it will also perform a garbage collection on the database.<\/p>\n<h2>General Syntax<\/h2>\n<pre>gbak &lt;options&gt; -user &lt;username&gt; -password &lt;password&gt; &lt;source&gt; &lt;destination&gt;<\/pre>\n<h4>Backup<\/h4>\n<p>For backups, &lt;source&gt; is the database you want to back up, &lt;destination&gt; is the file name of the backup file. The usual extension for the backup file is .fbk for Firebird and .gbk for InterBase.<\/p>\n<p>Only SYSDBA or the database owner can perform a backup. For multi-file databases, specify only the name of the <i>first<\/i> file as the database name.<\/p>\n<h4>Restore<\/h4>\n<p>For restores, &lt;source&gt; is the backup file and &lt;destination&gt; is the name of the database that is to be built up from the backup file. You will have to specify the -C option for restore.<\/p>\n<h2>General Options<\/h2>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>-nodbtriggers<\/pre>\n<\/td>\n<td>Suppresses Database Triggers from running [Firebird 2.1]<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-pas[sword] &lt;password&gt;<\/pre>\n<\/td>\n<td>Database password<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-fet[ch_password] &lt;filename&gt;<\/pre>\n<\/td>\n<td>Instead of -password: Fetch password from the file so it is not visible in the command line. When &lt;filename&gt; is stdin, the user will be prompted for the password. [Firebird\u00a02.5]<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-m[etadata]<\/pre>\n<\/td>\n<td>Only backs up\/restores metadata (schema). No table data will be re\/stored.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-role &lt;role&gt;<\/pre>\n<\/td>\n<td>Connect as role<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-se[rvice]\r\n  &lt;hostname&gt;:service_mgr<\/pre>\n<\/td>\n<td>Backup: Creates the backup file on the database server, using the Service Manager.<br \/>\nRestore: Creates the database from a backup file on the server, using the Service Manager.<br \/>\nAll file names (backup file, log file) must be specified as viewn from the server&#8217;s perspective.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-u[ser] &lt;username&gt;<\/pre>\n<\/td>\n<td>Database user name<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-v[erbose] or<\/pre>\n<pre>-v[erify]<\/pre>\n<\/td>\n<td>Verbose output of what GBAK is doing<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-y &lt;filename&gt;<\/pre>\n<\/td>\n<td>Redirect all output messages to &lt;filename&gt;<br \/>\nThe file <i>must not<\/i> exist before running GBAK!<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-y suppress<\/pre>\n<\/td>\n<td>Quiet mode: suppress any output<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-z<\/pre>\n<\/td>\n<td>Show GBAK version and server version<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Backup Options<\/h2>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>-b[ackup_database]<\/pre>\n<\/td>\n<td>Back up. This switch is optional.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-co[nvert]<\/pre>\n<\/td>\n<td>Converts external tables to internal tables<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-e[xpand]<\/pre>\n<\/td>\n<td>Creates an uncompressed backup<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-fa[ctor] n<\/pre>\n<\/td>\n<td>Blocking factor for tape device<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-g[arbage collect]<\/pre>\n<\/td>\n<td>Does not perform garbage collection during backup, so the backup will be faster. When you plan to da a Restore or Sweep anyway after the backup.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-ig[nore]<\/pre>\n<\/td>\n<td>Ignores checksum errors while backing up<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-l[imbo]<\/pre>\n<\/td>\n<td>Ignores limbo transactions while backing up<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-m[etadata]<\/pre>\n<\/td>\n<td>Only backs up metadata (schema). No table data will be stored.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-nt<\/pre>\n<\/td>\n<td>Non-transportable format (use only when you know you will restore on same platform and database version)<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-t[ransportable]<\/pre>\n<\/td>\n<td>Creates a transportable backup (transportable between platforms and server versions). This is the default.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Restore Options<\/h2>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>-bu[ffers]<\/pre>\n<\/td>\n<td>Set cache size for restored database<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-c[reate_database]<\/pre>\n<\/td>\n<td>Restore to a new database (the target database file MUST NOT exist)<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-fix_fss_d[ata] &lt;charset&gt;<\/pre>\n<\/td>\n<td>Repair malformed UNICODE_FSS data during Restore [Firebird 2.5]<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-fix_fss_m[etadata] &lt;charset&gt;<\/pre>\n<\/td>\n<td>Repair malformed UNICODE_FSS metadata during Restore [Firebird 2.5]<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-i[nactive]<\/pre>\n<\/td>\n<td>All indexes will be restored as INACTIVE<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-k[ill]<\/pre>\n<\/td>\n<td>Does not create shadows that are defined in the backup<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-m[etadata]<\/pre>\n<\/td>\n<td>Only restores metadata (schema). No table data will be restored.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-mo[de] read_write<\/pre>\n<\/td>\n<td>Restores to a read\/write database (This is the default)<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-mo[de] read_only<\/pre>\n<\/td>\n<td>Restores to a read-only database<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-n[o_validity]<\/pre>\n<\/td>\n<td>Does not restore validity constraints. So you can restore data that does not meet these constraints and could not be restored otherwise.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-o[ne_at_a_time]<\/pre>\n<\/td>\n<td>Usually the restore takes place in one single transaction for the whole database. This switch puts a commit after each table. So you can use this to partially restore databases with corrupt table data.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-p[age_size] &lt;size&gt;<\/pre>\n<\/td>\n<td>Sets page size of new database. &lt;size&gt; can be one of 1024, 2048, 4096, 8192. Default is 1024.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-r[eplace_database]<\/pre>\n<\/td>\n<td>Restores over an existing database. This can only be performed by SYSDBA or the owner of the database that is overwritten. Do NOT restore over a database that is in use! [Firebird 1.0, 1.5]<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-rep[lace_database]<\/pre>\n<\/td>\n<td>New abbreviation for the old -replace_database [Firebird 2.0]<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-r[ecreate_database] o[verwrite]<\/pre>\n<\/td>\n<td>[Firebird 2.0] Restores over an existing database. This can only be performed by SYSDBA or the owner of the database that is overwritten. Do NOT restore over a database that is in use!-r is equivalent to -c. Only the &#8220;overwrite&#8221; option will restore over an existing database.<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>-use_[all_space]<\/pre>\n<\/td>\n<td>Normally, on restore, database pages will be filled to about 80\u00a0%. With the use_all_space option, database pages will be filled to 100\u00a0%. (Useful for read-only databases which will see no more modifications.)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Examples<\/h2>\n<h4>A regular Backup<\/h4>\n<p><code>gbak -v -t -user SYSDBA -password \"masterkey\" dbserver:\/db\/warehouse.fdb c:\\backups\\warehouse.fbk<\/code><\/p>\n<h4>Backup with output to a logfile<\/h4>\n<p><code>del c:\\backups\\warehouse.log<br \/>\ngbak -v -t -user SYSDBA -password masterkey <b>-y c:\\backups\\warehouse.log<\/b> dbserver:\/db\/warehouse.fdb c:\\backups\\warehouse.fbk<\/code><\/p>\n<h4>A regular Restore<\/h4>\n<p><code>gbak <b>-c<\/b> -v -user SYSDBA -password masterkey c:\\backups\\warehouse.fbk dbserver:\/db\/warehouse2.fdb<\/code><\/p>\n<h4>Restore to an already existing database (Firebird 1.0, 1.5)<\/h4>\n<p><code>gbak <b>-c -r<\/b> -v -user SYSDBA -password masterkey c:\\backups\\warehouse.fbk dbserver:\/db\/warehouse.fdb<\/code><\/p>\n<h4>Restore to an already existing database (Firebird 2.x)<\/h4>\n<p><code>gbak <b>-r o<\/b> -v -user SYSDBA -password masterkey c:\\backups\\warehouse.fbk dbserver:\/db\/warehouse.fdb<\/code><\/p>\n<h4>Create a read-only database<\/h4>\n<p><code>gbak -c -v <b>-mode read_only -use_all_space<\/b> -user SYSDBA -password masterkey c:\\backups\\warehouse.fbk c:\\files\\warehousedb.fdb<\/code><\/p>\n<h2>Multi-file backups<\/h2>\n<h4>Syntax for backup<\/h4>\n<p><code>gbak [options] &lt;database&gt; &lt;target file 1&gt; &lt;size 1&gt; &lt;target file 2&gt; &lt;size 2&gt; ... &lt;target file n&gt;<\/code><\/p>\n<p>NOTE: Do not specify a size for the last file. It will always be filled to take up what is left over, no matter how large.<\/p>\n<p>Size can be given in bytes (8192), kilobytes (1024k), megabytes (5m), or gigabytes (2g)<\/p>\n<h4>Syntax for restore<\/h4>\n<p><code>gbak -c [options] &lt;source file 1&gt; &lt;source file 2&gt; ... &lt;source file n&gt; &lt;database&gt;<\/code><\/p>\n<h2>Restoring to a multi-file database<\/h2>\n<p><code>gbak -c [options] &lt;source file&gt; &lt;db file 1&gt; &lt;size 1&gt; &lt;db file 2&gt; &lt;size 2&gt; ... &lt;db file n&gt;<\/code><\/p>\n<p>NOTE: Do not specify a size for the last database file. It can always grow unlimited to take up the rest.<\/p>\n<p>Size can be given in bytes (8192), kilobytes (1024k), megabytes (5m), or gigabytes (2g)<\/p>\n<h4>Restoring from a multi-file backup to a multi-file database<\/h4>\n<p><code>gbak -c [options] &lt;source\u00a0file\u00a01&gt; &lt;source\u00a0file\u00a02&gt; ... &lt;source\u00a0file\u00a0n&gt; &lt;db\u00a0file\u00a01&gt; &lt;size\u00a01&gt; &lt;db\u00a0file\u00a02&gt; &lt;size\u00a02&gt; ... &lt;db\u00a0file\u00a0n&gt;<\/code><\/p>\n<h2>Backup and Restore at the same time<\/h2>\n<p>Use this when you want to test the physical and logical health of your database or to copy a database to another location using a proper Backup-&amp;-Restore cycle.<\/p>\n<p>Note that <i>stdin<\/i> and <i>stdout<\/i> get special treatment from gbak here, so don&#8217;t use &#8220;\/dev\/stdin&#8221; or &#8220;\/dev\/stdout&#8221;.<\/p>\n<h4>Syntax<\/h4>\n<p><code>gbak -c [options] &lt;source database&gt; <b>stdout<\/b> <b>|<\/b> gbak -r [options] <b>stdin<\/b> &lt;target database&gt;<\/code><\/p>\n<h2>Backing up and Restoring the Security Database<\/h2>\n<h3>Firebird 1.0, 1.5<\/h3>\n<p>You can perform a regular backup of the security database.\u00a0 The security database resides in the Firebird directory. It is named<\/p>\n<ul>\n<li><i>ISC4.gdb<\/i> in Firebird 1.0 and<\/li>\n<li><i>security.fdb<\/i> in Firebird 1.5.<\/li>\n<\/ul>\n<h3>Firebird 2.x (using the Service Manager)<\/h3>\n<p>Firebird 2.x does not allow regular database access to the security database. Its name is now <i>security2.fdb<\/i><\/p>\n<p>The only way to access the security database is via the Service Manager. As GBAK can also use the Service Manager (Option -se), you can run a backup using this option. However, the backup file will also be written to the server machine.<\/p>\n<p>General Syntax:<\/p>\n<pre>gbak &lt;options&gt; -user &lt;username&gt; -password &lt;password&gt; -service &lt;servername&gt;:service_mgr &lt;sec-db-name&gt; &lt;backup-filename&gt;<\/pre>\n<p>Example:<\/p>\n<pre>gbak -v -t -user sysdba -password masterkey <b>-service dbserver:service_mgr<\/b> c:\\Programme\\Firebird2\\security2.fdb C:\\Backups\\Security2.fbk<\/pre>\n<pre>  (in this case, Security2.fbk will be written to the C:\\Backups folder of dbserver!)<\/pre>\n<p>When your database server listens on a non-default port:<\/p>\n<pre>gbak -v -t -user sysdba -password masterkey -se dbserver<b>\/3051<\/b>:service_mgr c:\\Programme\\Firebird2\\security2.fdb C:\\Backups\\Security2.fbk<\/pre>\n<h3>Firebird 2.1\/2.5<\/h3>\n<p>In Firebird 2.1 there is a new option -no_dbtriggers that suppresses database triggers from running during backup\/restore. So you can suppress any unwanted behaviour for the connection that GBAK needs to establish for the database.<\/p>\n<h2>Restoring the Security Database<\/h2>\n<p>It is not possible to restore the security database while Firebird is running. In case your security database gets destroyed, this is what you can do:<\/p>\n<ul>\n<li>Stop the Firebird service\/daemon<\/li>\n<li>Replace the current security database with a new one. If anything else fails, re-install the Firebird server<\/li>\n<li>You should now have a working SYSDBA login and password. If not, re-install the Firebird server &#8230;<\/li>\n<li>Start the Firebird service\/daemon<\/li>\n<li>Using GBAK, restore your backup of the security database to a temporary place (like C:\\Temp\\security2.fdb)<\/li>\n<li>Stop the Firebird service\/daemon again<\/li>\n<li>Now copy the file from the temporary place to the correct place in the Firebird folder<\/li>\n<li>Start the Firebird service\/daemon<\/li>\n<li>Now you should have your &#8220;old&#8221; security database back.<\/li>\n<li>Good Luck! \ud83d\ude42<\/li>\n<\/ul>\n<h2>Upgrading a Security Database to Firebird 2.0<\/h2>\n<p>There is a special chapter &#8220;Dealing with the New Security Database&#8221; about this in the Firebird 2.0 Release Notes, which get installed to the <i>doc<\/i> subdirectory of your Firebird directory. You should also take a look at the <i>misc\\upgrade\\security\\security_database.txt<\/i> file, which explains in detail how to do it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GBAK is Firebird&#8217;s command line tool for online backup and restore of a complete database. GBAK is able to perform a backup while the database is running. There is no need to shut down the database during a GBAK backup. GBAK will create a consistent snapshot of the database at the time it starts running. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[91,42,51,68],"tags":[248,162,246,247],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-banco-de-dados","category-leitura-recomendada","category-linux-linuxrs","category-redes-2","tag-backup","tag-firebird","tag-gbak","tag-restore"],"_links":{"self":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=433"}],"version-history":[{"count":1,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":434,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions\/434"}],"wp:attachment":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}