INIT v2.6

The INIT subcommand is used to create the BART backup catalog directory, rebuild the BART backupinfo file, and set the archive_command in the server based on the archive_command setting in the bart.cfg file.

Syntax:

bart INIT [ –s { <server_name> | all } ] [ -o ]

[ -r [ -i { <backup_id> | <backup_name> | all } ] ]

[--no-configure]

The following table describes the INIT options:

OptionsDescription
-s { <server_name> | all }
--server { <server_name> | all }
<server_name> is the name of the database server to which the INIT actions are to be applied. If all is specified or if the option is omitted, actions are applied to all servers.
-o
--override
Overrides the existing Postgres archive_command configuration parameter setting in the postgresql.conf file or the postgresql.auto.conf file using the BART archive_command parameter in the BART configuration file. The INIT generated archive command string is written to the postgresql.auto.conf file.
-r
--rebuild
Rebuilds the backupinfo file located in each backup subdirectory. If all is specified or if the option is omitted, the backupinfo files of all backups for the database servers specified by the -s option are recreated. This option is only intended for recovering from a situation where the backupinfo file has become corrupt.
If the backup was initially created with a user-defined backup name, and then the INIT -r option is invoked to rebuild that backupinfo file, the user-defined backup name is no longer available. Thus, future references to the backup must use the backup identifier.
-i { <backup_id> | <backup_name> | all }
--backupid { <backup_id> | <backup_name> | all }
<backup_id> is an integer, backup identifier and <backup_name> is the user-defined alphanumeric name for the backup. The -i option can only be used with the -r option.
--no-configurePrevents the archive_command from being set in the PostgreSQL server.

Examples

In the following code sample, you can see that archive_mode = off and archive_command is not set. After invoking the BART INIT subcommand, archive_mode is set to on and archive_command is set:

archive_mode = off # enables archiving; off, on, or always
# (change requires restart)
archive_command = ''
# command to use to archive a logfile segment
[edb@localhost bin]$ ./bart init -s ppas11
INFO: setting archive_mode/archive_command for server 'ppas11'
WARNING: archive_mode/archive_command is set. Restart the PostgreSQL
server using 'pg_ctl restart'
[edb@localhost bin]$
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
archive_mode = 'on'
archive_command = 'scp %p
edb@127.0.0.1:/home/edb/bkup/ppas11/archived_wals/%f'

In the following code sample, you can see that archive_mode = on, and archive_command is not set. After invoking the INIT subcommand, archive_command is set:

archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = '' # command to use to archive a logfile segment
[edb@localhost bin]$ ./bart init -s ppas11
INFO: setting archive_mode/archive_command for server 'ppas11'
WARNING: archive_command is set. Reload the configuration in the
PostgreSQL server using pg_reload_conf() or 'pg_ctl reload'
[edb@localhost bin]$
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
archive_command = 'scp %p
edb@127.0.0.1:/home/edb/bkup/ppas11/archived_wals/%f'

In the following code sample, you can see that archive_mode = on and archive_command are already set. After invoking the INIT subcommand, there is no change in their settings. Note that to override the existing archive_command, you must include the -o option.

archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'scp %p
edb@127.0.0.1:/home/edb/bkup/ppas11/archived_wals/%f' # command to use
to archive a logfile segment
# placeholders: %p = path of file to archive
[edb@localhost bin]$ ./bart init -s ppas11
INFO: setting archive_mode/archive_command for server 'ppas11'
WARNING: archive_command is not set for server 'ppas11'
[edb@localhost bin]$
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.

In the following code sample, you can see that archive_mode = off and archive_command is already set. After invoking the INIT subcommand archive_mode is set to on:

archive_mode = off # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'scp %p
edb@127.0.0.1:/home/edb/bkup/ppas11/archived_wals/%f' # command to use
to archive a log file segment
[edb@localhost bin]$ ./bart init -s ppas11
INFO: setting archive_mode/archive_command for server 'ppas11'
WARNING: archive_mode/archive_command is set. Restart the PostgreSQL
server using 'pg_ctl restart'
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
archive_mode = 'on'
archive_command = 'scp %p
edb@127.0.0.1:/home/edb/bkup/ppas11/archived_wals/%f'

In the following code sample an existing archive command setting is overridden by resetting the archive_command in the PostgreSQL server with the archive_command = 'cp %p %a/%f' parameter from the bart.cfg file:

[BART]

bart_host= enterprisedb@192.168.2.22
backup_path = /opt/backup_edb
pg_basebackup_path = /usr/edb/as11/bin/pg_basebackup
logfile = /tmp/bart.log
scanner_logfile = /tmp/bart_scanner.log

[ACCTG]

host = 127.0.0.1
port = 5444
user = repuser
cluster_owner = enterprisedb
archive_command = 'cp %p %a/%f'
description = "Accounting"

The archive_mode and archive_command parameters in the database server are set as follows:

edb=# SHOW archive_mode;
archive_mode
--------------
on
(1 row)
edb=# SHOW archive_command;
archive_command
------------------------------------------------------------------
scp %p bartuser@192.168.2.22:/opt/backup/acctg/archived_wals/%f

(1 row)

Invoke the INIT subcommand with the -o option to override the current archive_command setting in the PostgreSQL server:

-bash-4.1$ bart INIT -s acctg -o
INFO: setting archive_mode/archive_command for server 'acctg'
WARNING: archive_command is set. Reload the configuration in the
PostgreSQL server using pg_reload_conf() or 'pg_ctl reload'

Reload the database server configuration; a restart of the database server is not necessary to reset only the archive_command parameter:

[root@localhost tmp]# service ppas11 reload

The archive_command in the PostgreSQL server is now set as follows:

edb=# SHOW archive_command;
               archive_command
-----------------------------------------------
cp %p /opt/backup_edb/acctg/archived_wals/%f
(1 row)

The new command string is written to the postgresql.auto.conf file:

# Do not edit this file manually!
# It will be overwritten by ALTER SYSTEM command.
archive_command = 'cp %p /opt/backup_edb/acctg/archived_wals/%f'

When you invoke the BART INIT command with the -r option, BART rebuilds the backupinfo file using the content of the backup directory for the server specified or for all servers. The BART backupinfo file is initially created by the BACKUP subcommand and contains the backup information used by BART.

Note

If the backup was initially created with a user-defined backup name, and then the INIT -r option is invoked to rebuild the backupinfo file, the user-defined backup name is no longer available. Thus, future references to the backup must use the backup identifier.

The following code sample shows the backupinfo file location in a backup subdirectory:

[root@localhost acctg]# pwd
/opt/backup/acctg
[root@localhost acctg]# ls -l
total 4
drwx------ 2 enterprisedb enterprisedb 38 Oct 26 10:21 1477491569966
drwxrwxr-x 2 enterprisedb enterprisedb 4096 Oct 26 10:19 archived_wals
[root@localhost acctg]# ls -l 1477491569966
total 61144
-rw-rw-r-- 1 enterprisedb enterprisedb 703 Oct 26 10:19 backupinfo
-rw-rw-r-- 1 enterprisedb enterprisedb 62603776 Oct 26 10:19 base.tar

The following code sample displays the backupinfo file content:

BACKUP DETAILS:
BACKUP STATUS: active
BACKUP IDENTIFIER: 1477491569966
BACKUP NAME: none
BACKUP PARENT: none
BACKUP LOCATION: /opt/backup/acctg/1477491569966
BACKUP SIZE: 59.70 MB
BACKUP FORMAT: tar
BACKUP TIMEZONE:
XLOG METHOD: fetch
BACKUP CHECKSUM(s): 1
ChkSum File
84b3eeb1e3f7b3e75c2f689570d04f10 base.tar
TABLESPACE(s): 0
START WAL LOCATION: 2/A5000028 (file 0000000100000002000000A5)
STOP WAL LOCATION: 2/A50000C0 (file 0000000100000002000000A5)
CHECKPOINT LOCATION: 2/A5000028
BACKUP METHOD: streamed
BACKUP FROM: master
START TIME: 2016-10-26 10:19:30 EDT
LABEL: pg_basebackup base backup
STOP TIME: 2016-10-26 10:19:30 EDT
TOTAL DURATION: 0 sec(s)

The following code sample displays an error message if the backupinfo file is missing when invoking a BART subcommand:

-bash-4.2$ bart SHOW-BACKUPS
ERROR: 'backupinfo' file does not exist for backup '1477491569966'
please use 'INIT -r' to generate the file

The backupinfo file may be missing if the BACKUP subcommand did not complete successfully.

The following code sample displays information about rebuilding the backupinfo file of the specified backup for database server acctg:

-bash-4.1$ bart INIT -s acctg -r -i 1428346620427
INFO: rebuilding BACKUPINFO for backup '1428346620427' of server 'acctg'
INFO: backup checksum: ced59b72a7846ff8fb8afb6922c70649 of base.tar

The following code sample displays information about how the backupinfo files of all backups are rebuilt for all database servers:

-bash-4.1$ bart INIT -r

INFO: rebuilding BACKUPINFO for backup '1428347191544' of server 'acctg'
INFO: backup checksum: 1ac5c61f055c910db314783212f2544f of base.tar
INFO: rebuilding BACKUPINFO for backup '1428346620427' of server 'acctg'
INFO: backup checksum: ced59b72a7846ff8fb8afb6922c70649 of base.tar
INFO: rebuilding BACKUPINFO for backup '1428347198335' of server 'dev'
INFO: backup checksum: a8890dd8ab7e6be5d5bc0f38028a237b of base.tar
INFO: rebuilding BACKUPINFO for backup '1428346957515' of server 'dev'
INFO: backup checksum: ea62549cf090573625d4adeb7d919700 of base.tar

The following code sample displays information about invoking BART INIT with the -r - i option:

edb@localhost bin]$ ./bart init -s ppas11 -i 1551778898392 -r
INFO: rebuilding BACKUPINFO for backup '1551778898392' of server
'ppas11'
[edb@localhost bin]$ ls /home/edb/bkup/ppas11/1551778898392/
backupinfo backup_label base base-1.tar base-2.tar base-3.tar
base-4.tar base-5.tar base.tar

The following code sample displays information about invoking the BART INIT command with the --no-configure option. You can use the --no-configure option with the INIT subcommand to prevent the archive_command option from being set in the PostgreSQL server.

[edb@localhost bin]$ ./bart init -s ppas11 -o --no-configure
[edb@localhost bin]$
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.