Having reviewed the steps here in the FAQ, I thought it might be useful to create a helper script, possibly to be included with OctoPrint or OctoPi.
If you're more familiar with OctoPrint/OctoPi and the upgrade process than am I, then please comment and let me know if anything needs to be tweaked for this to be useful. Thanks in advance.
Notes:
- The restore side of things isn't 100% complete yet but the backup seems ready.
- Some of the commands in the restore section just echo to the screen rather than run.
- Includes syntax if called wrong.
- I believe the screen messages accurately describe what is about to happen, allowing the user to exit.
- If run once with the backup option, it will create a usable list of plugins later to reinstall.
- The backup option and instructions could be useful to simply back up the
.octoprint
folder area. - Uses standard UNIX methods of backing up folder structures with their timestamps intact.
- Includes a progress meter for long-running commands.
~/scripts/upgrade-help
#!/bin/sh
if [ $# -lt 1 ]
then
echo "Usage: ~/scripts/upgrade-help backup | restore"
exit 1
fi
if [ "$1" = "backup" ]
then
tput bold; echo This script will STOP the OctoPrint service, generate a list of the current set; tput sgr0
tput bold; echo "of plugins (overwriting the previous list) and create a tarball with instructions."; tput sgr0
echo ""
read -p "Do you want to continue? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo ""
echo First things first, we need to stop OctoPrint so that everything can be backed up:
sudo service octoprint stop
echo The OctoPrint service should now be stopped.
echo ""
echo Next, we need to create a list of your currently-running plugins for later reference:
cat ~/.octoprint/logs/octoprint.log |grep "|" | grep "= /home/pi/" | sort | uniq | sed 's|\|||g'> ~/.octoprint/current$
ls -l ~/.octoprint/current-plugins.txt
echo ""
echo Delete the previous backup if it exists:
rm ~/dot_octoprint.tar.gz 2> /dev/null
# Create a tarball in the home directory for the .octoprint folder structure
echo Next, we create a tarball of the ~/.octoprint folder:
tar -zcvf --atime-preserve=replace ~/dot_octoprint.tar.gz ~/.octoprint > /dev/null 2>&1 &
pid=$!
i=1
sp="/-\|"
echo -n ' '
while kill -0 $pid 2>/dev/null
do
printf '\b%.1s' "$sp"
sp=${sp#?}${sp%???}
sleep 0.1
done
printf '\b'
ls -l ~/dot_octoprint.tar.gz
echo ""
echo Now run the following command from your workstation to download it:
tput bold; echo scp pi@octopi.local:~/dot_octoprint.tar.gz \~/.; tput sgr0
echo ""
echo When you have upgraded your image and have remoted back
echo into your Pi, then run the following to upload the tarball:
tput bold; echo scp \~/dot_octoprint.tar.gz pi@octopi.local:\~/.; tput sgr0
echo ""
echo If you need OctoPrint running again, execute the following:
echo sudo service octoprint start
echo ""
fi
fi
if [ "$1" = "restore" ]
then
tput bold; echo This script will STOP the OctoPrint service, provide instructions for uploading your; tput sgr0
tput bold; echo previous backup and then ask you again if you would like to proceed.; tput sgr0
echo ""
read -p "Do you want to continue? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo ""
echo First things first, we need to stop OctoPrint so that everything can be updated:
sudo service octoprint stop
echo The OctoPrint service should now be stopped.
echo ""
echo Next, run the following command from your workstation to upload the backup
echo created earlier:
tput bold: echo scp \~/dot_octoprint.tar.gz pi@octopi.local:\~/.; tput sgr0
echo ""
echo You should see a backup file here:
ls -l ~/dot_octoprint.tar.gz
echo ""
echo If you did not see a file listed above, then you should not continue past
echo this point.
echo ""
echo This next step is potentially dangerous if you did not follow the earlier
echo instructions. You should have earlier run a remote scp command to download
echo and now to upload it back to your Raspberry Pi.
echo ""
read -p "Are you sure you want to delete the existing ~/.octoprint folder structure? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo ""
cd ~
echo Removing ~/.octoprint...
echo rm -rf ~/.octoprint
echo ""
echo Restoring ~/.octoprint...
echo tar -zxvf ~/dot_octoprint.tar.gz
echo ""
echo Now restarting the OctoPrint service...
echo sudo service octoprint start
echo
echo When it comes back up, you should now be able to open up OctoPrint in your browser
echo and log back in just like before\; however, your plugins are still missing. Go to
echo Settings \> Plugin Manager \> Get More... and install the plugins that are seen here:
cat ~/.octoprint/current-plugins.txt | grep -v bundled
fi
fi
fi