Backup and Restore procedure

Hi All,

On a maas server I’ve tried following the backup and restore procedures from:

However, it does not work correctly:

  1. for backing up and restoring the PostgreSQL DB. I used:
    sudo -u postgres pg_dump maas_db -c > “backup/$(date +%s)_maas_dump.sql”
    and
    sudo -u postgres psql maas_db < /home/ubuntu/backup/$(unix date)_maas_dump.sql
    That one actually worked for me, because previously I was having permission issues with the procedure presented in the docs.
  2. but for restoring the snap maas, it is where I am having issues. True we need to reinstall maas before running restore, like mentioned here: Issue restoring from backup
    Still, when restarts maas it does not remain active
$ sudo snap services maas
Service          Startup  Current   Notes
maas.supervisor  enabled  inactive  -
$ sudo snap logs maas
2025-08-20T06:44:57Z systemd[1]: Stopped Service for snap application maas.supervisor.
2025-08-20T06:44:57Z systemd[1]: Started Service for snap application maas.supervisor.
2025-08-20T06:44:57Z maas.supervisor[86775]: cannot create user data directory: /root/snap/maas/39713: No such file or directory
2025-08-20T06:44:57Z systemd[1]: snap.maas.supervisor.service: Main process exited, code=exited, status=1/FAILURE
2025-08-20T06:44:57Z systemd[1]: snap.maas.supervisor.service: Failed with result 'exit-code'.
2025-08-20T06:44:57Z systemd[1]: snap.maas.supervisor.service: Scheduled restart job, restart counter is at 5.
2025-08-20T06:44:57Z systemd[1]: Stopped Service for snap application maas.supervisor.
2025-08-20T06:44:57Z systemd[1]: snap.maas.supervisor.service: Start request repeated too quickly.
2025-08-20T06:44:57Z systemd[1]: snap.maas.supervisor.service: Failed with result 'exit-code'.
2025-08-20T06:44:57Z systemd[1]: Failed to start Service for snap application maas.supervisor.

Does anyone have the correct procedure for backing up and restoring MAAS? ( that is not the one presented on the official documentation )

Best Regards

Hi @migmeneses

It looks like snap is looking for a MAAS version that is not found in the system.

39713 is MAAS 3.4. If you ran sudo snap install maas in a clean environment, it will install the latest.

Could you try to install 3.4 and try again?
sudo snap install maas --channel=3.4/stable?

Hello Javier,

These are the steps followed:

Back up MAAS

Create a backup directory:

mkdir -p backup

Dump the database:

sudo -u postgres pg_dump maas_db -c > "backup/$(date +%s)_maas_dump.sql"

Stop MAAS:

sudo snap stop maas

Stop PostgreSQL:

sudo systemctl stop postgresql.service

Save a snap backup:

sudo snap save maas

Export the snapshot:

sudo snap export-snapshot <snapshot-id> backup/$(date +%s)_snapshot

Restart services:

sudo systemctl start postgresql.service
sudo snap restart maas

Restore MAAS

Stop and remove the MAAS snap:

sudo snap stop maas && sudo snap remove --purge maas

Restore the database:

sudo -u postgres psql maas_db < /home/ubuntu/backup/1755604162_maas_dump.sql

(Re)Install MAAS and stop:

sudo snap install --channel=3.4/stable maas
sudo snap services maas ( check if the snap is "active" )
sudo snap stop maas

Import and restore the snapshot:

sudo snap import-snapshot backup/<snapshot>
sudo snap restore <snapshot-id>

Restart services:

sudo systemctl restart postgresql.service
sudo snap restart maas

On sudo snap install --channel=3.4/stable maas I noticed MAAS is not configured if I run maas status and after sudo snap restore it is when i cannot (re)start maas again.

Regards

The idea here is to have a smooth, reliable and confident backup and restore procedure.

What if you run sudo snap install --revision <revision-number-from-backup> instead, during the restoration? This will bring you from snapstore the same revision as the one present in the snapshot. --channel 3.4/stable will bring the latest revision available in 3.4/stable channel, which at the moment is 39713 for amd64.

These are the last entries:

sudo -u postgres psql maas_db < /home/ubuntu/backup/1755863836_maas_dump.sql
sudo snap import-snapshot backup/1755863946_snapshot
sudo snap install --revision 39713 maas
sudo snap services maas 

Service was active:

ubuntu@poc-1:~$ sudo snap services maas                                                                                                                                                
Service          Startup  Current  Notes                                                                                                                                               
maas.supervisor  enabled  active   -       

but,

$ sudo maas status
cannot create user data directory: /root/snap/maas/39713: No such file or directory                                                                                                    

( be aware of this:

sudo ls -l /root/snap/maas/
total 8
drwxr-xr-x 2 root root 4096 Aug 22 11:53 39713
drwxr-xr-x 2 root root 4096 Aug 22 11:53 common
lrwxrwxrwx 1 root root    5 Aug 22 12:10 current -> 39713

so the directory exist )

Restore:

sudo snap restore <snapshot-id>

Restart services:

sudo systemctl restart postgresql.service
sudo snap restart maas

and from there, maas is not active anymore.
I think the problem sits just before running snap restore

logs:

ubuntu@poc-1:~$ sudo snap logs maas
2025-08-22T12:14:02Z systemd[1]: Stopped Service for snap application maas.supervisor.
2025-08-22T12:14:02Z systemd[1]: Started Service for snap application maas.supervisor.
2025-08-22T12:14:02Z maas.supervisor[7326]: cannot create user data directory: /root/snap/maas/39713: No such file or directory
2025-08-22T12:14:02Z systemd[1]: snap.maas.supervisor.service: Main process exited, code=exited, status=1/FAILURE
2025-08-22T12:14:02Z systemd[1]: snap.maas.supervisor.service: Failed with result 'exit-code'.
2025-08-22T12:14:02Z systemd[1]: snap.maas.supervisor.service: Scheduled restart job, restart counter is at 5.
2025-08-22T12:14:02Z systemd[1]: Stopped Service for snap application maas.supervisor.
2025-08-22T12:14:02Z systemd[1]: snap.maas.supervisor.service: Start request repeated too quickly.
2025-08-22T12:14:02Z systemd[1]: snap.maas.supervisor.service: Failed with result 'exit-code'.
2025-08-22T12:14:02Z systemd[1]: Failed to start Service for snap application maas.supervisor.

I went through the backup process using the PostgreSQL 16 and MAAS 3.6 and I reached the same outcome.

Could you open a bug with this information?

Filed bug:

For my own curiosity, were you able to roll back without issues?

No,
After running maas snap restore, it does not restore the maas snap correctly
The log says it cannot find directory /root/snap/maas/
when it actually exists

Weird,
Today, I just started maas

sudo snap start maas

Checked:

sudo snap service maas

and is running

Interesting that re-starting MAAS after some downtime seems to have fixed it. I wonder if there’s some long running process that didn’t complete in time for your first MAAS restart?

Could be,
Be aware that my actions Create Backup and Restore are happening continuously.

Maybe, there should be a cooldown period before running restore.

Yesterday, 2025-08-27
Created a new backup, trying to restore it today, and back to square 1

syslog:

Aug 28 08:45:40 poc-1 systemd[1]: Stopped PostgreSQL RDBMS.
Aug 28 08:45:40 poc-1 systemd[1]: Stopping PostgreSQL RDBMS...
Aug 28 08:45:40 poc-1 systemd[1]: Stopping PostgreSQL Cluster 17-main...
Aug 28 08:45:45 poc-1 systemd[1]: postgresql@17-main.service: Deactivated successfully.
Aug 28 08:45:45 poc-1 systemd[1]: Stopped PostgreSQL Cluster 17-main.
Aug 28 08:45:45 poc-1 systemd[1]: postgresql@17-main.service: Consumed 7min 19.342s CPU time.
Aug 28 08:45:45 poc-1 systemd[1]: Starting PostgreSQL Cluster 17-main...
Aug 28 08:45:47 poc-1 systemd[1]: Started PostgreSQL Cluster 17-main.
Aug 28 08:45:47 poc-1 systemd[1]: Starting PostgreSQL RDBMS...
Aug 28 08:45:47 poc-1 systemd[1]: Finished PostgreSQL RDBMS.
Aug 28 08:45:47 poc-1 systemd[1]: Started Service for snap application maas.supervisor.
Aug 28 08:45:48 poc-1 maas.supervisor[203920]: cannot create user data directory: /root/snap/maas/39713: No such file or directory
Aug 28 08:45:48 poc-1 systemd[1]: snap.maas.supervisor.service: Main process exited, code=exited, status=1/FAILURE
Aug 28 08:45:48 poc-1 systemd[1]: snap.maas.supervisor.service: Failed with result 'exit-code'.
Aug 28 08:45:48 poc-1 systemd[1]: snap.maas.supervisor.service: Scheduled restart job, restart counter is at 1.

Today 2025-09-01,
I was available to start MAAS services without any major issues.
sudo snap start maas

So, it looks like:

  1. The regular procedure shown for backup and restore in the official docs is not reliable.
  2. There is a cool-down period before (re)starting Maas services successfully!

I am going to try this on another environment and see the results!

Tried on DigitalOcean droplets, and same result.