Skip to content

Backup and Restore

Kyle Gabriel edited this page Aug 8, 2022 · 12 revisions

This guide also exists as an article on the forum, 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.

Mycodo

Mycodo can be backed up and restored from the web UI, under the Configure -> Backup Restore page. This is the preferred method for backing up and restoring Mycodo settings and measurement data.

However, if you cannot access this page or prefer to do it from the command line, the following sections will show you how.

Full Mycodo Backup (install directory and settings, no measurements)

sudo /bin/bash ~/Mycodo/mycodo/scripts/upgrade_commands.sh backup-create

Restore a Full Mycodo Backup

sudo /bin/bash ~/Mycodo/mycodo/scripts/upgrade_commands.sh backup-restore <restore_backup>

Replace <restore_backup> with the backup you would like restored. It must be the full location. Use the following command to see what backups exist.

ls -l /var/Mycodo-backups

Example output

pi@raspberry:~$ ls -l /var/Mycodo-backups
drwxrwxr-x 9 mycodo mycodo 4096 Jun 19 23:33 Mycodo-backup-2017-06-23_02-07-50-5.0.35
drwxrwxr-x 9 mycodo mycodo 4096 Jun 19 23:33 Mycodo-backup-2017-07-06_19-04-27-5.0.41

The full restore command to select the earlier version from this example would be

sudo /bin/bash ~/Mycodo/mycodo/scripts/upgrade_commands.sh backup-restore /var/Mycodo-backups/Mycodo-backup-2017-07-06_19-04-27-5.0.41

Restoring a Backup Downloaded from the Backup Page

If you downloaded a zip archive of a backup, it's a little more involved to restore. You will have to transfer the zip archive to the system you want to install or restore to, then extract the archive. If a ~/Mycodo directory already exists, you will need to rename it to make room for the restore. The directory you just extracted your backup to will then need to be renamed to ~/Mycodo. Then, if this is a system that has never had Mycodo installed before, run this command:

sudo ~/Mycodo/install/setup.sh

Otherwise, if you are restoring this to a system that has had Mycodo installed before, run this command to get the restore running:

sudo ~/Mycodo/mycodo/scripts/upgrade_post.sh

You may need to reboot after the script finishes to complete the restore.

InfluxDB Database Backup (measurements)

influxd backup -database mycodo_db -portable <path to save backup>

Restore the InfluxDB Database Backup

If you are restoring the mycodo influxdb database on a system that has not yet had Mycodo installed but influxdb is installed, you can merely execute the following command.

influxd restore -portable -newdb mycodo_db <path to influxdb backup>

However, a more likely scenario is you already have Mycodo installed, and in this case, you already have an influxdb database named mycodo_db that you cannot just "add" new data to by executing the restore command. You will need to restore your backed up data to a temporary database, copy the measurements from the temporary database to the mycodo database, then delete the temporary database.

First, restore the backed up data to a temporary database.

influxd restore -portable -db mycodo_db -newdb mycodo_db_bak <path to influxdb backup>

Next, copy the measurements and delete the temporary database. This may take a while if there's a lot of data.

influx
> USE mycodo_db_bak
> SELECT * INTO mycodo_db..:MEASUREMENT FROM /.*/ GROUP BY *
> DROP DATABASE mycodo_db_bak