How to backup and restore Landscape¶
This guide describes the suggested method for backing up and restoring a self-hosted Landscape Server.
It covers:
Backup and restore of the Landscape Server database using PostgreSQL point-in-time recovery (PITR)
Backup of Landscape Server configuration files required to restore the application server
Testing recovery procedures on a spare server
It doesn’t cover:
Juju deployments using Charmed PostgreSQL, which was introduced in the 24.04 LTS release of the Landscape Server charm. See the guide on backing up and restoring a charmed deployment and Charmed PostgreSQL’s backup and restore documentation for information on backing up and restoring your charmed database.
Backup of Landscape Clients
PostgreSQL tuning or general database administration beyond what’s required for PITR
Backup of Landscape Clients isn’t covered due to the wide variety of client environments (physical hardware, VMs, containers, some permanent and others ephemeral). In many deployments, client-side data doesn’t need to be backed up because clients can re-register with Landscape Server and the main records are stored server-side.
It is strongly recommended that administrators of a self-hosted Landscape instance familiarize themselves with PITR facilities and PostgreSQL’s archived logging, also called write-ahead logging (WAL). Some syntactic configuration changes have occurred across PostgreSQL versions, so you should select the documentation for your particular PostgreSQL server version:
PostgreSQL 16 (Ubuntu 24.04 LTS)
PostgreSQL 14 (Ubuntu 22.04 LTS)
High availability (HA)¶
If you operate an HA deployment, perform the PostgreSQL backup and recovery steps per database instance in the cluster, and back up Landscape configuration files on each Landscape Server node.
Define a backup and retention policy¶
To configure PostgreSQL for continuous archiving and PITR:
When should base backups be taken?
Recommended: Daily or weekly depending on volume of WAL logs and desired recovery speed.
How many base backups should be retained at any given time?
This dictates the earliest point in time to which you can initially restore.
Where should WAL logs be archived to?
Recommended: A separate machine or some form of networked and secure storage.
Where should base backups be stored?
Recommended: The same machine as the WAL archive so that all materials necessary for restoration are available in one place.
Although it’s possible to backup and archive on the same machine as the PostgreSQL server, it is recommended that you use a separate machine for base backup and archived log storage. This is to allow restoration in case the server becomes inaccessible for any reason. We also recommend that any other files needed to restore the Landscape application server (such as the configuration files listed in a following section) are also copied to this location to allow recovery of the entire service from one location.
Configure PostgreSQL for continuous archiving and PITR¶
To configure PostgreSQL:
In the
postgresql.confconfiguration file, setwal_level,archive_mode, andarchive_commandaccording to the PostgreSQL documentation for your server’s version.Test that your
archive_commandoperates correctly in all circumstances and check the results of thearchive_commandin the PostgreSQL logs:Force a WAL switch, then verify a new WAL file appears in your archive location:
sudo -u postgres psql -c "SELECT pg_switch_wal();"
Check the PostgreSQL logs for archiving messages and ensure the archive command completed successfully (exit code is 0).
Once you’re confident the configuration is correct, restart the PostgreSQL service to activate archived logging.
Monitor the archive destination to ensure logs begin to appear there.
(Optional) If your server has very low traffic, you may want to use the
archive_timeoutsetting to force archiving of partial logs after a timeout.When WAL logs are being archived successfully, construct a script that executes
pg_basebackupand stores the result in your base backup storage destination.Test that this operates correctly as the cluster owner (typically
postgres).Add a cronjob to periodically execute this script (as the cluster owner).
Note that you don’t need to take Landscape offline to perform these backups; pg_basebackup can only execute when the cluster is up. There’s no need to worry about inconsistency between Landscape’s various databases either: a base backup represents the state of the cluster across all databases within it at the instant the backup starts.
Backup server configuration files¶
The following files should also be copied from your Landscape Server(s) to your backup destination to ensure that restoration of the Landscape application server is also possible:
/etc/landscape/*: Landscape configuration files and the on-premises Landscape license/etc/default/landscape-server: Specifies which Landscape application services start on a given machine/etc/apache2/sites-available/<server-name>: The Landscape Apache vhost configuration file, usually named after the FQDN of the server/etc/ssl/certs/<landscape-cert>: The Landscape server X.509 certificate/etc/ssl/private/<landscape-cert>: The Landscape server X.509 key file/etc/postgresql/<pg-version>/main/*: Various PostgreSQL configuration files
You may also want to backup the following log files. They’re not required for normal operation of Landscape Server, but may provide additional information in the case of service outages:
/var/log/landscape-server/*: The Landscape Server log files
If any of these files change periodically (e.g., the SSL certificates), you may also want to set up a cronjob to handle backing-up these files regularly.
Test recovery procedures¶
We recommend that administrators of self-hosted Landscape test their recovery procedures after configuring their Landscape Server(s) for archived logging and PITR. This is to ensure that backups are valid and restorable, and that administrators are familiar with these procedures.
To test the recovery procedures:
Provision a spare server (or servers) and install Landscape Server as you have on your production machine(s)
Stop the Landscape application server, and the PostgreSQL cluster on the spare
Copy configuration files (see prior section) to the spare; you may wish to keep a script handy to perform this task in your backup location
If your spare isn’t installed from scratch (e.g. if it is installed from an image), remove everything under
/var/lib/landscape/hash-id-databasesRestore a recent PostgreSQL base-backup onto the spare; this usually involves (re)moving the existing PostgreSQL cluster’s data directory (e.g.
/var/lib/postgresql/<pg-version>/main) and replacing it with the contents of the base-backup (or un-tarring the base-backup into it, if tar format was chosen); ensure file ownership and modes are preserved!Configure recovery settings in the PostgreSQL cluster’s data directory by setting recovery configuration options in
postgresql.conf(e.g.,restore_command). See the “Archive Recovery” documentation section in that file for examples and documentation of recovery settings. Then, create an emptyrecovery.signalfile in the cluster data directory to trigger recovery mode.Start the PostgreSQL cluster on the spare and watch the PostgreSQL logs to ensure recovery proceeds by retrieving and replaying WAL logs. Upon completion, PostgreSQL 14+ will automatically remove the
recovery.signalfile.Once recovery is complete, run
/opt/canonical/landscape/hash-id-databasesto regenerate the hash databases cacheFinally, start the Landscape application server on the spare and test it to verify correct operation, including:
The UI loads and you can log in
Existing data (accounts, computers, activities) is present
Connected clients remain registered and are reporting data
Landscape services are active and healthy (e.g.,
sudo lsctl statusshows the services as active)