AMPGSQL(8)

πŸ’… AMPGSQL(8) πŸ’…

okay bestie, welcome to the ampgsql page from the System Administration Commands section of the manual β€” she's niche, she's powerful, and she's about to back up your Postgres without ever taking it offline. iykyk. 🫢


✨ NAME ✨

ampgsql β€” the Amanda Application that lets Amanda interface with PostgreSQL. it's giving "backup bestie" energy fr fr.


🌸 DESCRIPTION 🌸

So like, Ampgsql is an Amanda Application API script. that means she is not for you to run by hand, bestie β€” do not just type her name into a terminal and expect magic, because that is not the vibe. πŸ’€

What she does do is implement on-line backups of PostgreSQL databases in conjunction with WAL archiving. iconic behaviour, honestly.

πŸ“’ Note: Tablespaces are not currently supported. not me crying about it. 😭
⚠️ Note: on versions of PostgreSQL earlier than 8.2, if the database is quiet during a full backup, then the backup may not complete until enough database activity takes place to trigger the archiving of the current WAL file. so consider adjusting the PG-MAX-WAL-WAIT property from its default (60s) to compensate. but heads up β€” you will need to increase dtimeout on the server accordingly. πŸ•

πŸ¦‹ DISKLIST πŸ¦‹

the diskdevice must be the cluster data directory. so if it's "/var/lib/pgsql/data", you go:

HOST DISKNAME /var/lib/pgsql/data DUMPTYPE

or

HOST /var/lib/pgsql/data DUMTYPE

literally pick one, no cap. ⭐


πŸ‘‘ OPERATION πŸ‘‘

this application implements the backup strategy described at http://www.postgresql.org/docs/current/static/continuous-archiving.html. educated queen. πŸ“š

For a level zero (full) backup, ampgsql will:

  • execute PG_START_BACKUP()
  • dump the data directory
  • execute PG_STOP_BACKUP()
  • wait for the final WAL file to be archived
  • back up the required WAL files
  • optionally delete WAL files that are no longer necessary

the two dumps are made with GNU Tar, to data_dir.tar and archive_dir, respectively. then they get combined into a single tar file. πŸ’–

A level N backup creates a single tar file containing all WAL files since the previous level N-1 backup. incremental slay. ✨


πŸŽ€ PROPERTIES πŸŽ€

this section lists the amanda.conf(5) properties that control ampsql's functionality. see amanda-applications(7) for the tea on application properties and how they're configured. β˜•

  • ARCHIVEDIR β€” the directory that WAL segment files get archived to, as specified by the archive_command in PostgreSQL's postgresql.conf. the amanda user on the client must have at least read and execute permission on this directory, and preferably write. without write permission, Amanda cannot clean up expired WAL and backup files. πŸ™ˆ
  • CLEANUPWAL β€” whether or not to remove old WAL segment files during base backups. defaults to yes.
  • DB β€” the database to connect to. defaults to "template1" (which exists by default, thankfully 🫢).
  • DIRECTORY β€” for the restore command only; the data is recovered in that directory. must be a unix path.
  • FULL-WAL β€” which WAL files to archive when doing a full backup:
    • FULL β€” backup all WAL files since the previous full backup.
    • INCR β€” backup all WAL files since the previous backup (incr or full).
    • NO β€” backup all WAL files required for that full backup.
    • the default is "INCR". πŸ’…
  • GNUTAR-PATH β€” path to the GNU tar executable. this option only has an effect during restore. the default is set when Amanda is built by the --with-gnutar configure option.
  • HOST β€” host to connect to. if it starts with "/" it will be interpreted as a directory that holds the socket file. PostgreSQL defaults to /tmp.
  • INCREMENTAL β€” default: NO. if set to "YES", then backup only the WAL files since the previous backup. it reduces the size of the backup, but amanda will not be able to restore all incrementals β€” the restore must be done manually. it is easier to set the dumptype bump* parameter to force a bump at every backup. 😭
  • MAX-WAL-WAIT β€” the maximum amount of time to wait for PG_STOP_BACKUP to archive a WAL file. in versions of PostgreSQL before 8.2, PG_STOP_BACKUP does not automatically archive the latest WAL file, so a quiet database may wait a very long time before archiving the WAL file. default: 60 seconds. set to 0 to wait forever. πŸ•°οΈ
  • PASSFILE β€” connect using the credentials in this file. each line should have the format "hostname:port:database:username:password". the permissions must permit it to be read only by the user, or the file will not be used. only usable with Postgres 8.1 and up.
  • PORT β€” the TCP port to connect to, or the suffix of the socket file. PostgreSQL defaults to 5432.
  • PSQL-PATH β€” path to the psql binary. if not specified, the PATH environment variable will be searched. πŸ”
  • REMOVE-FULL-WAL β€” default: YES. remove all WAL files included in the full backup.
  • REMOVE-INCREMENTAL-WAL β€” default: NO. if set to "YES" then remove all WAL files included in the incremental backup.
  • STATEDIR β€” directory for saving state about backups already made. the default is set when Amanda is built by the --with-gnutar-listdir configure option.
  • TMPDIR β€” directory to use for temporary files during the backup process. it should have enough space to store a complete copy of the database. the default is set when Amanda is built by the --with-tmpdir configure option.
  • USER β€” user to connect as. it must be a superuser. πŸ‘‘
  • VERBOSE β€” do not use the --quiet output of psql.

🌈 CLIENT PROPERTIES 🌈

⚠️ client properties are deprecated. all properties should be set in the dumptype. periodt.

this section lists the amanda-client.conf(5) properties that control ampsql's functionality. so here's the cute part: if a property is prefixed with the diskname and an underscore, then it will be used when that diskname is being backed up. for example, if the properties PG-DATADIR and foo-PG-DATADIR are set, the value of PG-DATADIR will be used when bar and baz are being backed up, but foo-PG-DATADIR will be used when foo is being backed up. disknames are specified in the disklist(5). πŸ’–

  • PG-ARCHIVEDIR β€” the directory that WAL segment files are archived to, as specified by the archive_command in PostgreSQL's postgresql.conf. the amanda user on the client must have at least read and execute permission on this directory, and preferably write. without write permission, Amanda cannot clean up expired WAL and backup files. πŸ™ˆ
  • PG-CLEANUPWAL β€” whether or not to remove old WAL segment files during base backups. defaults to yes.
  • PG-DATADIR β€” cluster data directory.
  • PG-DB β€” database to connect to. defaults to "template1" (which exists by default).
  • PG-HOST β€” host to connect to. if it starts with "/" it will be interpreted as a directory that holds the socket file. PostgreSQL defaults to /tmp.
  • PG-MAX-WAL-WAIT β€” the maximum amount of time to wait for PG_STOP_BACKUP to archive a WAL file. in versions of PostgreSQL before 8.2, PG_STOP_BACKUP does not automatically archive the latest WAL file, so a quiet database may wait a very long time before archiving the WAL file. default: 60 seconds. set to 0 to wait forever. πŸ•°οΈ
  • PG-PASSFILE β€” connect using the credentials in this file. each line should have the format "hostname:port:database:username:password". the permissions must permit it to be read only by the user, or the file will not be used. only usable with Postgres 8.1 and up.
  • PG-PASSWORD β€” password to use when connecting. deprecated in favor of passfiles. πŸ’€
  • PG-PORT β€” the TCP port to connect to, or the suffix of the socket file. PostgreSQL defaults to 5432.
  • PG-USER β€” user to connect as. it must be a superuser.
  • PSQL-PATH β€” path to the psql binary. if not specified, the PATH environment variable will be searched.

🧚 RECOVERY 🧚

🚨 read the postgres documentation carefully before attempting a recovery. this section is only a rough guide to the process. do not come for me if you skip the docs, bestie. 😭

The data recovered from a postgres backup consists of a data tarball and one or more archive tarballs. the data contains the state of the database at the time the full backup was performed, and the archive tarballs contain postgres WAL files that must be re-run to generate a consistent state. ✨

  1. Ensure that the database server is shut down, and move the existing data directory aside.
  2. Untar the data tarball over this directory, and verify that ownership and permissions are correct.
  3. Untar all of the archive tarballs into a single directory β€” the archive directory.
  4. Create a recovery.conf in the data directory, owned by the proper user and with proper permissions.
  5. Add a restore_command to it, e.g.
restore_command = 'cp /path/to/archive_dir/%f "%p"'
  1. Start the database server, and examine the logs to track the process of the recovery.

When the recovery is complete, the server will transition into a running state, and will move the recovery.conf file aside so that it will not attempt a recovery on the next invocation. main character energy tbh. πŸ‘‘


⭐ EXAMPLE ⭐

In amanda.conf:

define application app_ampgsql {
  plugin "ampgsql"
  property "HOST" "localhost"
  property "ARCHIVEDIR" "/tmp/archivedir"
  property "PASSFILE" "/etc/amanda/ampgsql.passwd"
}
define dumptype dump_ampgsql {
  global
  program "APPLICATION"
  application app_ampgsql
}

The disklist file:

  localhost /var/lib/pgsql/data dump_ampgsql

or

  localhost postgres /var/lib/pgsql/data dump_ampgsql

πŸ”₯ SEE ALSO πŸ”₯

amanda(8), amanda.conf(5), amanda-client.conf(5), amanda-applications(7)

The Amanda Wiki: http://wiki.zmanda.com/ β€” go read it, she ate. πŸ’…


πŸ“ AUTHOR πŸ“

Nikolas Coukouma <atrus@zmanda.com> Zmanda, Inc. (http://www.zmanda.com)


okay that's the whole page, bestie β€” written by hand with love. this icon was brought to you by Amanda 3.5.4, dated 07/23/2025. now go archive those WAL files and slay πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from