How to Backup and Restore Mycodo

This guide also exists as a wiki article on the Mycodo github, so much of this information has been duplicated to make it easier to find. Refer to both of these documents to understand and attempt to restore your system before asking for assistance.

Restoring a Mycodo backup or exported configuration is often done to fix a broken system, clone a configuration on a new system, or restore a previous backup if an upgrade failed.

There are different types of backups, therefore to properly determine the method to restore, you will need to first become familiar with some terminology surrounding the backup-restore system.

  • InfluxDB Database and Metastore Backup (More β†’ Export Import Page) - This is an export of the InfluxDB measurement database as a ZIP archive. It contains all measurements in an InfluxDB-specific format, and allows you to restore measurements to InfluxDB running on a working Mycodo system. This data requires the exact same inputs/functions to be able to be properly associated and viewed in Mycodo, therefore if you are importing this backup, you will also need to import the Mycodo Settings Data Backup.

  • Mycodo Settings Data Backup (More β†’ Export Import Page) - This is an export of the system configuration/settings, such as settings for Inputs, Outputs, and Functions, as well as the general configuration options. This also saves any custom Inputs, Outputs, Functions, etc. you previously imported. This is required to be imported if you are also importing the InfluxDB Database and Metastore Backup but you do not necessarily need to import the InfluxDB Database and Metastore Backup if you only want to restore your settings and don’t care to restore previously-saved measurements.

  • Full Mycodo System Backup (Config β†’ Backup Restore Page) - This is a backup of the entire Mycodo directory, except the /env Python virtual environment and camera images. Although you can download a ZIP archive of this backup directory for safe keeping, there is no simple import/restore functionality like there is for the Mycodo Settings Data Backup like there is on the More β†’ Export Import Page. This type of backup is only meant to allow easy restoring of a backup on the system is was created on, not to be transferred to another system. If you want to clone a system, use the Mycodo Settings Data Backup.

Export Import Page

The Mycodo Settings Data Backup is the single most important backup file you can have from a Mycodo system. With this file, you can completely replicate or restore all your settings on a fresh install of Mycodo. It is advised to save this file after making any significant changes to your Mycodo configuration, because if there is an issue (SD card stops working, upgrade failure, etc.), you can import this file and restore your entire system from the Export Import Page.

Backup Restore Page

Backup and Restore a Full Mycodo System Backup from the Web UI

During an upgrade, a Full Mycodo System Backup is created. A backup can also be created at any time by pressing the Create Backup button. This is an archive of the entire Mycodo directory (except the env/ Python virtual environment sub-directory). The most common time to use this is if you upgrade and find a part of your system is not working, or you want to return your system to a particular point in time you created a backup. Restoring a backup can be done by clicking the Restore button next to the backup you would like to restore.

Restoring a Full Mycodo System Backup from the Command Line

If you find the web UI no longer works after upgrading, restoring a backup from the command line is how you can restore your system to a previous working configuration. Log in to a terminal on your affected system and navigate to /var/Mycodo-backups and you should see a number of directories:

pi@rpi:/var/Mycodo-backups $ ls -l
drwxrwxr-x 11 mycodo mycodo 4096 Dec  4  2021 Mycodo-backup-2021-12-04_11-39-42-8.12.8
drwxrwxr-x 12 mycodo mycodo 4096 Mar 28 18:47 Mycodo-backup-2022-03-28_18-46-52-8.12.9
drwxrwxr-x 11 mycodo mycodo 4096 Mar 28 21:48 Mycodo-backup-2022-03-28_21-48-25-8.13.0
drwxrwxr-x 11 mycodo mycodo 4096 Mar 29 18:16 Mycodo-backup-2022-03-29_18-16-46-8.13.1
drwxrwxr-x 10 mycodo mycodo 4096 Apr  1 18:43 Mycodo-backup-2022-04-01_18-43-20-8.13.2
drwxrwxr-x 10 mycodo mycodo 4096 Apr  3 13:49 Mycodo-backup-2022-04-03_13-49-18-8.13.3

To restore one of these backups, you will need to copy the exact directory name into the following command:

sudo ~/Mycodo/mycodo/scripts/ backup-restore /var/Mycodo-backups/Mycodo-backup-2022-04-03_13-49-18-8.13.3

Downloading and Restoring from a Full Mycodo System Backup

On the Backup Restore Page, you can also download any of these backups as an archive file. To use this archive to restore a system, you will need to transfer this archive to a new system, extract the contents to the ~/Mycodo directory, then run ~/Mycodo/install/, which will execute the install commands. Since this is a backup of a system, the configuration settings will be preserved from the time it was backed up.