How to back up MAAS

MAAS currently does not provide specific tools to back up and restore a working MAAS configuration. MAAS servers are part of your data centre, just like other Linux-based servers, so your current backup and disaster recovery solution should be sufficient to back up your MAAS environment. Even so, you should know which files and actions are critical – to ensure that you get a clean backup, and further ensure that you can restore it cleanly.

To back up your MAAS snap instance and restore it elsewhere, follow these steps:

  1. Backup your PostgreSQL database to a file called dump.sql in your home directory:
sudo -u postgres pg_dumpall -c > ~/dump.sql
  1. Ensure this has completed and that there are no other established sessions with the following command:
sudo -u postgres psql -c  "SELECT * FROM pg_stat_activity"

Running sessions, such as pg_dumpall, will appear in the application_name column of the output alongside psql running the above pg_stat_activity query.

  1. Stop the PostgreSQL service:
sudo systemctl stop postgresql.service
  1. Stop the MAAS snap service:
sudo snap stop maas
  1. Take a snapshot of the snap service:
sudo snap save maas

Note the snapshot id (number) that this command returns.

  1. Verify that the snapshot is valid:
sudo snap check-snapshot <snapshot-id>
  1. Export the snapshot to some external media:
sudo snap export-snapshot <snapshot-id> <external-media-path/snapshot-filename>

Be sure to restart the MAAS service if you plan to continue to use the current configuration, with:

sudo snap restart maas

Otherwise, you can leave MAAS stopped.

  1. If reinstalling MAAS on the same system, use the following command to completely remove the old MAAS instance from your system:
sudo snap remove --purge maas
  1. Restore the PostgreSQL dump with the following command:
sudo -u postgres psql -f dump.sql postgres
  1. Restart the PostgreSQL service:
sudo systemctl start postgresql.service
  1. Install the MAAS snap (same version) on your target machine, using the standard installation instructions for the version you’re (re)installing.

  2. Import the snapshot onto your target machine:

sudo snap import-snapshot <external-media-path/snapshot-filename>

The import function should give you the same snapshot ID. If an existing snapshot has the same number (shouldn’t happen here), that snapshot is overwritten.

  1. Restore the snapshot:
sudo snap restore <snapshot-id>
  1. Reset the database triggers with the following command:
sudo maas-region dbupgrade

You only need to run this command on one of the Region Controllers in a multi-region MAAS cluster.

At this point, you should be up and running with a restored MAAS backup.

To back up your MAAS snap instance and restore it elsewhere, follow these steps:

  1. Backup your PostgreSQL database to a file called dump.sql in your home directory:
sudo -u postgres pg_dumpall -c > ~/dump.sql
  1. Ensure this has completed and that there are no other established sessions with the following command:
sudo -u postgres psql -c  "SELECT * FROM pg_stat_activity"

Running sessions, such as pg_dumpall, will appear in the application_name column of the output alongside psql running the above pg_stat_activity query.

  1. Stop MAAS-related services:
sudo systemctl stop postgresql.service
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
  1. Archive the DB backup and the needed MAAS configuration files to an external drive with the following command:
sudo tar cvpzf <some-external-path>/backup.tgz --exclude=/var/lib/maas/boot-resources /etc/maas /var/lib/maas ~/dump.sql

If you’re not replacing the existing MAAS, make sure to restart the services you stopped prior to completing the backup.

How to restore the system when needed

To restore the MAAS backup to a new machine:

  1. Start with a freshly-updated installation of Ubuntu on identical hardware.

  2. Reinstall MAAS via the standard installation procedure.

  3. Stop the following services (note that PostgreSQL needs to keep running):

sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
  1. Copy the backup file to the new machine and untar its contents:
sudo tar xvzpf backup.tgz
  1. Restore the database with the following command:
sudo -u postgres psql -f dump.sql postgres
  1. Copy across the old configuration files to their new locations, taking care to move the originals aside just in case:
sudo sh -c "mv /etc/maas /etc/_maas; mv /var/lib/maas /var/lib/_maas"
sudo sh -c "cp -prf etc/maas /etc/; cp -prf var/lib/maas /var/lib/"

Take care to preserve the correct permissions when restoring files and directories.

  1. If your restore process regenerated the /var/lib/maas/secret file, make sure update this secret on any additional rack controllers.

  2. Reset the database triggers:

sudo maas-region dbupgrade

You only need to run this command on one of the Region Controllers in a multi-region MAAS cluster.

  1. Restart the stopped services:
sudo systemctl start maas-dhcpd.service
sudo systemctl start maas-rackd.service
sudo systemctl start maas-regiond.service

At this point, you should be up and running with a restored MAAS backup.


Last updated 21 days ago.