How to back up MAAS

MAAS uses standard command-line utilities for simple, familiar backups. The options described here allow you to either back up and restore everything MAAS-related, or just back up key packages and files.

Clean reset backup

The method uses pg_dumpall the entire database and make a complete snapshot of MAAS.

Back up procedure

  1. Find the PostgreSQL service:
    sudo systemctl list-units --type=service | grep postgres
    
  2. Create backup directory:
    mkdir -p <backup-path>/$(date +%s)
    
  3. Dump database:
    sudo -u postgres pg_dumpall -c > "<backup-path>/$(date +%s)_dump.sql"
    
  4. Stop MAAS:
    sudo snap stop maas
    
  5. (Optional) Stop PostgreSQL:
    sudo systemctl stop postgresql.service
    
  6. Snap backup:
    sudo snap save maas
    
  7. Export snapshot:
    sudo snap export-snapshot <snapshot-id> <backup-path>/$(date +%s)_snapshot
    
  8. Restart services:
    sudo systemctl start postgresql.service
    sudo snap restart maas
    

Restore

  1. Stop MAAS & remove instance:
    sudo snap stop maas && sudo snap remove maas
    
  2. Restore database:
    sudo -u postgres psql -f <backup-path>/<dump.sql> postgres
    
  3. Import & restore snapshot:
    sudo snap import-snapshot <backup-path>/<snapshot>
    sudo snap restore <snapshot-id>
    
  4. Restart services:
    sudo systemctl start postgresql.service
    sudo snap restart maas
    

Package backup

Backs up PostgreSQL and key MAAS files.

Backup

  1. Find PostgreSQL service:
    sudo systemctl list-units --type=service | grep postgres
    
  2. Create backup directory:
    mkdir -p <backup-path>/$(date +%s)
    
  3. Dump database:
    sudo -u postgres pg_dumpall -c > "<backup-path>/$(date +%s)_dump.sql"
    
  4. Stop MAAS services:
    sudo systemctl stop maas-dhcpd.service maas-rackd.service maas-regiond.service
    
  5. (Optional) Stop PostgreSQL:
    sudo systemctl stop postgresql.service
    
  6. Archive MAAS files:
    sudo tar cvpzWf <backup-path>/$(date +%s)_maas_backup.tgz --exclude=/var/lib/maas/boot-resources /etc/maas /var/lib/maas
    
  7. Restart services:
    sudo systemctl start postgresql.service
    sudo snap restart maas
    

Restore

  1. Reinstall Ubuntu (if possible).
  2. Ensure PostgreSQL is installed.
  3. Restore database:
    sudo -u postgres psql -f <backup-path>/<dump.sql> postgres
    
  4. Install MAAS from packages.
  5. Stop MAAS services:
    sudo systemctl stop maas-dhcpd.service maas-rackd.service maas-regiond.service
    
  6. Extract backup:
    sudo tar xvzpf <backup-path>/<backup.tgz> -C /
    
  7. Restart services:
    sudo systemctl start postgresql.service
    sudo systemctl restart maas-dhcpd.service maas-rackd.service maas-regiond.service
    

This document assumes MAAS is installed on Bionic and it is missing instructions how to backup on Focal.
Those maas-*.service which should be stopped are not present in MAAS 3.1 on Focal.

thanks, @marosg. making a note to test backup on focal and see what else might have changed.

Found a bug.

I had a borked snap upgrade of MAAS - it was an upgrade from MAAS 2.9 to 3.0 on Bionic, and it got stuck on a migration which I presume isn’t totally compatible with Postgres 10. The migrations which did run look harmless enough, but as a side effect of the upgrade errors, views were dropped.

I found the reference to ā€œsudo maas-region dbupgradeā€ on this page, however for the snap what I really needed was ā€œsudo snap run --shell maas -c ā€˜maas-region dbupgradeā€™ā€ (which I found from others internally). After running that, the views were restored.

TL;DR: The docs should note the appropriate ā€œmaas-region dbupgradeā€ command to use when running MAAS from snaps.

1 Like

The following lines in the documentation are numbered the same and are out of order. If you run the second command to restore the database, the server isn’t up because it was stopped in step #3.

#8. Restore the PostgreSQL dump with the following command:
sudo -u postgres psql -f dump.sql postgres

#8. Restart the PostgreSQL service:
sudo systemctl start postgresql.service

These should be swapped and re-numbered to #8 and #9.

@jfleach, edited; thank you for pointing out this error.

The backup procedure of the deb package install mentions a snap command to start maas again. It should be systemctl commands instead.

@camille.rodriguez :: gaah! thanks for the close review! will fix.

I believe we are missing a step in ā€œDo a clean restore of a snap installā€;

MAAS isn’t reinstalled during this process, so this command should fail (restoring a snapshot doesn’t reinstall the snap, it merely restore $SNAP_COMMON and things). Add a step to reinstall MAAS (with perhaps a link-out to the install and upgrade pages?)

This likewise appears in ā€œDo a minimal downtime restore of a MAAS snap installā€.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.