Errors or typos? Topics missing? Hard to read? Let us know.
MAAS uses standard command-line utilities to keep backups simple and familiar.
Clean reset backup
This procedure does a clean reset backup using pg_dumpall
. MAAS and PostgreSQL are fully overwritten on restore. You can also do a limited back 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.
Clean Snap backup
- Use this command, if needed, to confirm the local PostgreSQL service name:
sudo systemctl list-units --type=service | grep postgres
- Create an epoch-stamped directory on your external media to store the backup:
cd <external-backup-media>/maas-backups/
mkdir $(date +%s)
- Backup the database to your external backup media:
sudo -u postgres pg_dumpall -c > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_dump.sql"
- Stop MAAS:
sudo snap stop maas
- (Optional) Confirm that no other PostgreSQL sessions are active:
sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"
- (Optional) Stop PostgreSQL:
sudo systemctl stop postgresql.service
- Take a snapshot of MAAS and note the snapshot ID:
sudo snap save maas
- Verify the snapshot:
sudo snap check-snapshot <snapshot-id>
- Export the snapshot to your external backup media:
sudo snap export-snapshot <snapshot-id> <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_snapshot_<snapshot-id>
- (Optional) Restart PostgreSQL:
sudo systemctl start postgresql.service
- (Optional) Verify that PostgreSQL is running:
sudo systemctl status postgresql
- Restart MAAS:
sudo snap restart maas
Clean Snap restore
- Stop MAAS to clear any cache:
sudo snap stop maas
- Remove the current MAAS instance:
sudo snap remove maas
- Do a clean restore of the database:
sudo -u postgres psql -f <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_dump.sql postgres
- (Optional) Confirm that no other PostgreSQL sessions are active:
sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"
- (Optional) Stop PostgreSQL:
sudo systemctl stop postgresql.service
- Import the MAAS snapshot from external media:
sudo snap import-snapshot <external-backup-media>/maas-backups/<backup-timestamp>/<snapshot-epoch>_maas_snapshot_<snapshot-id>
- Restore the MAAS snapshot:
sudo snap restore <snapshot-id>
- (Optional) Restart PostgreSQL:
sudo systemctl start postgresql.service
- (Optional) Verify that PostgreSQL is running:
sudo systemctl status postgresql
- Restart MAAS:
sudo snap restart maas
Clean package backup
- Use this command, if needed, to confirm the local PostgreSQL service name:
sudo systemctl list-units --type=service | grep postgres
- Create an epoch-stamped directory on your external media to store the backup:
cd <external-backup-media>/maas-backups/
mkdir $(date +%s)
- Backup the database to your external backup media:
sudo -u postgres pg_dumpall -c > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_dump.sql"
- Stop MAAS services:
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
- (Optional) Confirm that no other PostgreSQL sessions are active:
sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"
- (Optional) Stop PostgreSQL:
sudo systemctl stop postgresql.service
- Write a verified archive of the key MAAS files to your external backup:
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
- (Optional) Restart PostgreSQL:
sudo systemctl start postgresql.service
- (Optional) Verify that PostgreSQL is running:
sudo systemctl status postgresql
- Restart MAAS:
sudo snap restart maas
Clean package restore
-
(Optional, but recommended if possible) Begin with a fresh Ubuntu install.
-
Make sure the required PostgreSQL version is installed.
-
Use this command, if needed, to confirm the local PostgreSQL service name:
sudo systemctl list-units --type=service | grep postgres
- Do a clean restore of the database:
sudo -u postgres psql -f <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_dump.sql postgres
-
Install MAAS from packages.
-
Once fully operational, stop these MAAS services:
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
- (Optional) Confirm that no other PostgreSQL sessions are active:
sudo -u postgres psql -c "SELECT * FROM pg_stat_activity"
- (Optional) Stop PostgreSQL:
sudo systemctl stop postgresql.service
- Untar the backup to a temporary directory:
mkdir /tmp/maas_backup
sudo tar xvzpf <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_backup.tgz -C /tmp/maas_backup
- Create epoch-stamped backup directories:
backup_dir="/var/backups/maas_backup/$(date +%s)"
sudo mkdir -p "$backup_dir"
- Move current MAAS directories to backup:
sudo mv /etc/maas "$backup_dir/etc_maas"
sudo mv /var/lib/maas "$backup_dir/var_lib_maas"
- Restore MAAS configuration from backup:
sudo cp -prf /tmp/maas_backup/etc/maas /etc/
sudo cp -prf /tmp/maas_backup/var/lib/maas /var/lib/
- Do a clean restore of the database:
sudo -u postgres psql -f <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_dump.sql postgres
- (Optional) Restart PostgreSQL:
sudo systemctl start postgresql.service
- (Optional) Verify that PostgreSQL is running:
sudo systemctl status postgresql
- Restart MAAS services:
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
Limited backup
For MAAS and PostgreSQL setups which are shared with other services, follow these backup and restore guidelines.
Limited Snap backup
- Use this command, if needed, to confirm the local PostgreSQL service name:
sudo systemctl list-units --type=service | grep postgres
- Create an epoch-stamped directory on your external media to store the backup:
cd <external-backup-media>/maas-backups/
mkdir $(date +%s)
- Identify the MAAS database that you want to back up:
sudo -u postgres psql
\l
# identifying the MAAS database is up to you
\q
- Backup the database to your external backup media:
sudo -u postgres pg_dump [maas_database_name] > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_only_backup.sql"
- Stop MAAS:
sudo snap stop maas
- Take a snapshot of MAAS and note the snapshot ID:
sudo snap save maas
- Verify the snapshot:
sudo snap check-snapshot <snapshot-id>
- Export the snapshot to your external backup media:
sudo snap export-snapshot <snapshot-id> <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_snapshot_<snapshot-id>
- Restart MAAS:
sudo snap restart maas
Limited Snap restore
- Stop MAAS to clear any cache:
sudo snap stop maas
- Remove the current MAAS instance:
sudo snap remove maas
- Do a limited restore of the MAAS database only:
sudo -u postgres psql [maas_database_name] < <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_maas_only_backup.sql
- Import the MAAS snapshot from external media:
sudo snap import-snapshot <external-backup-media>/maas-backups/<backup-timestamp>/<snapshot-epoch>_maas_snapshot_<snapshot-id>
- Restore the MAAS snapshot:
sudo snap restore <snapshot-id>
- Restart MAAS:
sudo snap restart maas
Limited package backup
- Use this command, if needed, to confirm the local PostgreSQL service name:
sudo systemctl list-units --type=service | grep postgres
- Create an epoch-stamped directory on your external media to store the backup:
cd <external-backup-media>/maas-backups/
mkdir $(date +%s)
- Identify the MAAS database that you want to back up:
sudo -u postgres psql
\l
# identifying the MAAS database is up to you
\q
- Backup the database to your external backup media:
sudo -u postgres pg_dump [maas_database_name] > "<external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_only_backup.sql"
- Stop MAAS services:
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
- Write a verified archive of the key MAAS files to your external backup:
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
- Restart MAAS:
sudo snap restart maas
Limited package restore
- Use this command, if needed, to confirm the local PostgreSQL service name:
sudo systemctl list-units --type=service | grep postgres
- Do a limited restore of the MAAS database only:
sudo -u postgres psql [maas_database_name] < <external-backup-media>/maas-backups/<backup-timestamp>/<dump_epoch>_maas_only_backup.sql
- Untar the MAAS backup to a temporary directory:
mkdir /tmp/maas_backup
sudo tar xvzpf <external-backup-media>/maas-backups/<backup-timestamp>/$(date +%s)_maas_backup.tgz -C /tmp/maas_backup
- Create epoch-stamped backup directories:
backup_dir="/var/backups/maas_backup/$(date +%s)"
sudo mkdir -p "$backup_dir"
- Move current MAAS directories to backup:
sudo mv /etc/maas "$backup_dir/etc_maas"
sudo mv /var/lib/maas "$backup_dir/var_lib_maas"
- Remove the current MAAS installation
sudo apt-get remove --purge maas
sudo apt-get autoremove
-
Install MAAS from packages.
-
Once fully operational, stop these MAAS services:
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
- Restore MAAS configuration from backup:
sudo cp -prf /tmp/maas_backup/etc/maas /etc/
sudo cp -prf /tmp/maas_backup/var/lib/maas /var/lib/
- Restart MAAS services:
sudo systemctl stop maas-dhcpd.service
sudo systemctl stop maas-rackd.service
sudo systemctl stop maas-regiond.service
Last updated 6 months ago.