Offline docs (switch to live docs)                          UI-only  CLI-only

How to back up MAAS

Without regular backups, you risk irreversible data loss and costly recovery efforts

Errors or typos? Topics missing? Hard to read? Let us know!

MAAS uses standard command-line utilitlies to keep backups simple and familiar.

Clean reset backup and restore

This procedure does a clean reset backup using pg_dumpall. MAAS and PostgreSQL are fully overwritten on restore. You can also do a targeted backup and restore if other services are sharing your PostgreSQL database.

Generally, using pg_dumpall for a database dump doesn't require stopping PostgreSQL. It works with live databases, ensuring consistent backups and minimal service disruption. The PostgreSQL transactional model guarantees dump accuracy. You should be able to keep PostgreSQL running -- skipping the optional steps below -- but you should stop MAAS first to avoid conflicts during the dump. If you're concerned at all, just use the optional steps to stop and restart PostgreSQL.

Please note that the order of steps is important.

Make a clean backup of a snap install

  1. Use this command, if needed, to confirm the local PostgreSQL service name:

nohighlight sudo systemctl list-units --type=service | grep postgres

  1. Create an epoch-stamped directory on your external media to store the backup:

nohighlight cd <external-backup-media>/maas-backups/ mkdir $(date +%s)

  1. Backup the database to your external backup media:

nohighlight sudo -u postgres pg_dumpall -c > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_dump.sql"

  1. Stop MAAS:

nohighlight sudo snap stop maas

  1. (Optional) Confirm that no other PostgreSQL sessions are active:

nohighlight sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"

  1. (Optional) Stop PostgreSQL:

nohighlight sudo systemctl stop postgresql.service

  1. Take a snapshot of MAAS and note the snapshot ID:

nohighlight sudo snap save maas

  1. Verify the snapshot:

nohighlight sudo snap check-snapshot <snapshot-id>

  1. Export the snapshot to your external backup media:

nohighlight sudo snap export-snapshot <snapshot-id> <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_snapshot_<snapshot-id>

  1. (Optional) Restart PostgreSQL:

nohighlight sudo systemctl start postgresql.service

  1. (Optional) Verify that PostgreSQL is running:

nohighlight sudo systemctl status postgresql

  1. Restart MAAS:

nohighlight sudo snap restart maas

Do a clean restore of a snap install

  1. Stop MAAS to clear any cache:

nohighlight sudo snap stop maas

  1. Remove the current MAAS instance:

nohighlight sudo snap remove maas

  1. Do a clean restore of the database:

nohighlight sudo -u postgres psql -f <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_dump.sql postgres

  1. (Optional) Confirm that no other PostgreSQL sessions are active:

nohighlight sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"

  1. (Optional) Stop PostgreSQL:

nohighlight sudo systemctl stop postgresql.service

  1. Import the MAAS snapshot from external media:

nohighlight sudo snap import-snapshot <external-backup-media>/maas-backups/<backup-timestamp>/<snapshot-epoch>_maas_snapshot_<snapshot-id>

  1. Restore the MAAS snapshot:

nohighlight sudo snap restore <snapshot-id>

  1. (Optional) Restart PostgreSQL:

nohighlight sudo systemctl start postgresql.service

  1. (Optional) Verify that PostgreSQL is running:

nohighlight sudo systemctl status postgresql

  1. Restart MAAS:

nohighlight sudo snap restart maas

Make a clean backup of a package install

  1. Use this command, if needed, to confirm the local PostgreSQL service name:

nohighlight sudo systemctl list-units --type=service | grep postgres

  1. Create an epoch-stamped directory on your external media to store the backup:

nohighlight cd <external-backup-media>/maas-backups/ mkdir $(date +%s)

  1. Backup the database to your external backup media:

nohighlight sudo -u postgres pg_dumpall -c > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_dump.sql"

  1. Stop MAAS services:

nohighlight sudo systemctl stop maas-dhcpd.service sudo systemctl stop maas-rackd.service sudo systemctl stop maas-regiond.service

  1. (Optional) Confirm that no other PostgreSQL sessions are active:

nohighlight sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"

  1. (Optional) Stop PostgreSQL:

nohighlight sudo systemctl stop postgresql.service

  1. Write a verified archive of the key MAAS files to your external backup:

nohighlight sudo tar cvpzWf <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_backup.tgz --exclude=/var/lib/maas/boot-resources /etc/maas /var/lib/maas

  1. (Optional) Restart PostgreSQL:

nohighlight sudo systemctl start postgresql.service

  1. (Optional) Verify that PostgreSQL is running:

nohighlight sudo systemctl status postgresql

  1. Restart MAAS:

nohighlight sudo snap restart maas

Do a clean restore of a package install

  1. (Optional, but recommended if possible) Begin with a fresh Ubuntu install.

  2. Make sure the required PostgreSQL version is installed.

  3. Use this command, if needed, to confirm the local PostgreSQL service name:

nohighlight sudo systemctl list-units --type=service | grep postgres

  1. Do a clean restore of the database:

nohighlight sudo -u postgres psql -f <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_dump.sql postgres

  1. Install MAAS from packages.

  2. Once fully operational, stop these MAAS services:

nohighlight sudo systemctl stop maas-dhcpd.service sudo systemctl stop maas-rackd.service sudo systemctl stop maas-regiond.service

  1. (Optional) Confirm that no other PostgreSQL sessions are active:

nohighlight sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"

  1. (Optional) Stop PostgreSQL:

nohighlight sudo systemctl stop postgresql.service

  1. Untar the backup to a temporary directory:

nohighlight mkdir /tmp/maas_backup sudo tar xvzpf <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_backup.tgz -C /tmp/maas_backup

  1. Create epoch-stamped backup directories:

nohighlight backup_dir="/var/backups/maas_backup/$(date +%s)" sudo mkdir -p "$backup_dir"

  1. Move current MAAS directories to backup:

nohighlight sudo mv /etc/maas "$backup_dir/etc_maas" sudo mv /var/lib/maas "$backup_dir/var_lib_maas"

  1. Restore MAAS configs from backup:

nohighlight sudo cp -prf /tmp/maas_backup/etc/maas /etc/ sudo cp -prf /tmp/maas_backup/var/lib/maas /var/lib/

  1. Do a clean restore of the database:

nohighlight sudo -u postgres psql -f <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_dump.sql postgres

  1. (Optional) Restart PostgreSQL:

nohighlight sudo systemctl start postgresql.service

  1. (Optional) Verify that PostgreSQL is running:

nohighlight sudo systemctl status postgresql

  1. Restart MAAS services:

nohighlight sudo systemctl stop maas-dhcpd.service sudo systemctl stop maas-rackd.service sudo systemctl stop maas-regiond.service

Limited backup and restore

For MAAS and PostgreSQL setups which are shared with other services, follow these backup and restore guidelines.

Make a minimal-downtime backup of a snap install

  1. Use this command, if needed, to confirm the local PostgreSQL service name:

nohighlight sudo systemctl list-units --type=service | grep postgres

  1. Create an epoch-stamped directory on your external media to store the backup:

nohighlight cd <external-backup-media>/maas-backups/ mkdir $(date +%s)

  1. Identify the MAAS database that you want to back up:

nohighlight sudo -u postgres psql \l # identifying the MAAS database is up to you \q

  1. Backup the database to your external backup media:

nohighlight sudo -u postgres pg_dump [maas_database_name] > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_only_backup.sql"

  1. Stop MAAS:

nohighlight sudo snap stop maas

  1. Take a snapshot of MAAS and note the snapshot ID:

nohighlight sudo snap save maas

  1. Verify the snapshot:

nohighlight sudo snap check-snapshot <snapshot-id>

  1. Export the snapshot to your external backup media:

nohighlight sudo snap export-snapshot <snapshot-id> <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_snapshot_<snapshot-id>

  1. Restart MAAS:

nohighlight sudo snap restart maas

Do a minimal downtime restore of a MAAS snap install

  1. Stop MAAS to clear any cache:

nohighlight sudo snap stop maas

  1. Remove the current MAAS instance:

nohighlight sudo snap remove maas

  1. Do a limited restore of the MAAS database only:

nohighlight sudo -u postgres psql [maas_database_name] < <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_maas_only_backup.sql

  1. Import the MAAS snapshot from external media:

nohighlight sudo snap import-snapshot <external-backup-media>/maas-backups/<backup-timestamp>/<snapshot-epoch>_maas_snapshot_<snapshot-id>

  1. Restore the MAAS snapshot:

nohighlight sudo snap restore <snapshot-id>

  1. Restart MAAS:

nohighlight sudo snap restart maas

Make a minimal-downtime backup of a package install

  1. Use this command, if needed, to confirm the local PostgreSQL service name:

nohighlight sudo systemctl list-units --type=service | grep postgres

  1. Create an epoch-stamped directory on your external media to store the backup:

nohighlight cd <external-backup-media>/maas-backups/ mkdir $(date +%s)

  1. Identify the MAAS database that you want to back up:

nohighlight sudo -u postgres psql \l # identifying the MAAS database is up to you \q

  1. Backup the database to your external backup media:

nohighlight sudo -u postgres pg_dump [maas_database_name] > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_only_backup.sql"

  1. Stop MAAS services:

nohighlight sudo systemctl stop maas-dhcpd.service sudo systemctl stop maas-rackd.service sudo systemctl stop maas-regiond.service

  1. Write a verified archive of the key MAAS files to your external backup:

nohighlight sudo tar cvpzWf <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_backup.tgz --exclude=/var/lib/maas/boot-resources /etc/maas /var/lib/maas

  1. Restart MAAS:

nohighlight sudo snap restart maas

Do a minimal-downtime restore of a package install

  1. Use this command, if needed, to confirm the local PostgreSQL service name:

nohighlight sudo systemctl list-units --type=service | grep postgres

  1. Do a limited restore of the MAAS database only:

nohighlight sudo -u postgres psql [maas_database_name] < <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_maas_only_backup.sql

  1. Untar the MAAS backup to a temporary directory:

nohighlight mkdir /tmp/maas_backup sudo tar xvzpf <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_backup.tgz -C /tmp/maas_backup

  1. Create epoch-stamped backup directories:

nohighlight backup_dir="/var/backups/maas_backup/$(date +%s)" sudo mkdir -p "$backup_dir"

  1. Move current MAAS directories to backup:

nohighlight sudo mv /etc/maas "$backup_dir/etc_maas" sudo mv /var/lib/maas "$backup_dir/var_lib_maas"

  1. Remove the current MAAS installation

nohighlight sudo apt-get remove --purge maas sudo apt-get autoremove

  1. Install MAAS from packages.

  2. Once fully operational, stop these MAAS services:

nohighlight sudo systemctl stop maas-dhcpd.service sudo systemctl stop maas-rackd.service sudo systemctl stop maas-regiond.service

  1. Restore MAAS configs from backup:

nohighlight sudo cp -prf /tmp/maas_backup/etc/maas /etc/ sudo cp -prf /tmp/maas_backup/var/lib/maas /var/lib/

  1. Restart MAAS services:

nohighlight sudo systemctl stop maas-dhcpd.service sudo systemctl stop maas-rackd.service sudo systemctl stop maas-regiond.service