add backup

This commit is contained in:
paukstelis
2022-06-16 19:58:00 -04:00
parent c4b9b4b68c
commit cfeecb28e7
2 changed files with 52 additions and 10 deletions

View File

@@ -46,6 +46,8 @@ These files provide a simple bash script for quickly deploying multiple octoprin
* Test USB connections * Test USB connections
* Want to get rid of everything? `sudo octoprint_deploy/octoprint_deploy.sh remove` * Want to get rid of everything? `sudo octoprint_deploy/octoprint_deploy.sh remove`
# Recent Changes # Recent Changes
* Added webcam restart to system commands during
* Added ability to restart all non-template instances from the command line: `sudo octoprint_deploy/octoprint_deploy.sh restart_all`
* Admin user and first run wizards during Prepare System. * Admin user and first run wizards during Prepare System.
* Better uuid uniquification * Better uuid uniquification
* ArchLinux support * ArchLinux support

View File

@@ -14,7 +14,11 @@ get_settings() {
#Get octoprint_deploy settings, all of which are written on system prepare #Get octoprint_deploy settings, all of which are written on system prepare
if [ -f /etc/octoprint_deploy ]; then if [ -f /etc/octoprint_deploy ]; then
TYPE=$(cat /etc/octoprint_deploy | sed -n -e 's/^type: \(\.*\)/\1/p') TYPE=$(cat /etc/octoprint_deploy | sed -n -e 's/^type: \(\.*\)/\1/p')
#echo $TYPE if [ "$TYPE" == linux ]; then
OCTOEXEC="sudo -u $user /home/$user/OctoPrint/bin/octoprint"
else
OCTOEXEC="sudo -u $user /home/$user/oprint/bin/octoprint"
fi
STREAMER=$(cat /etc/octoprint_deploy | sed -n -e 's/^streamer: \(\.*\)/\1/p') STREAMER=$(cat /etc/octoprint_deploy | sed -n -e 's/^streamer: \(\.*\)/\1/p')
#echo $STREAMER #echo $STREAMER
HAPROXY=$(cat /etc/octoprint_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p') HAPROXY=$(cat /etc/octoprint_deploy | sed -n -e 's/^haproxy: \(\.*\)/\1/p')
@@ -110,7 +114,7 @@ new_instance () {
if [ -f /etc/octoprint_instances ]; then if [ -f /etc/octoprint_instances ]; then
if grep -q $PORT /etc/octoprint_instances; then if grep -q $PORT /etc/octoprint_instances; then
echo "Port may be in use! Check /etc/octoprint_instances and select a different port. Exiting." | log echo "Port may be in use! Check /etc/octoprint_instances and select a different port. Exiting." | log
exit 1 main_menu
fi fi
fi fi
@@ -264,8 +268,6 @@ new_instance () {
$DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set plugins.errortracking.unique_id $(uuidgen) $DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set plugins.errortracking.unique_id $(uuidgen)
$DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set plugins.tracking.unique_id $(uuidgen) $DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set plugins.tracking.unique_id $(uuidgen)
$DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set serial.port /dev/octo_$INSTANCE $DAEMONPATH --basedir $OCTOCONFIG/.$INSTANCE config set serial.port /dev/octo_$INSTANCE
#Set port
#sed -i "/serial:/a\ port: /dev/octo_$INSTANCE" $OCTOCONFIG/.$INSTANCE/config.yaml
if [[ -n $CAM || -n $USBCAM ]]; then if [[ -n $CAM || -n $USBCAM ]]; then
write_camera write_camera
@@ -353,8 +355,7 @@ write_camera() {
echo "webcam:" >> $OCTOCONFIG/.$INSTANCE/config.yaml echo "webcam:" >> $OCTOCONFIG/.$INSTANCE/config.yaml
echo " snapshot: http://$(hostname).local:$CAMPORT?action=snapshot" >> $OCTOCONFIG/.$INSTANCE/config.yaml echo " snapshot: http://$(hostname).local:$CAMPORT?action=snapshot" >> $OCTOCONFIG/.$INSTANCE/config.yaml
echo " stream: http://$(hostname).local:$CAMPORT?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml echo " stream: http://$(hostname).local:$CAMPORT?action=stream" >> $OCTOCONFIG/.$INSTANCE/config.yaml
echo $OCTOEXEC --basedir $OCTOCONFIG/.$INSTANCE config append_value --json system.actions "{\"action\": \"Reset video streamer\", \"command\": \"sudo systemctl restart cam_$INSTANCE\", \"name\": \"Restart webcam\"}"
#Either Serial number or USB port #Either Serial number or USB port
#Serial Number #Serial Number
if [ -n "$CAM" ]; then if [ -n "$CAM" ]; then
@@ -387,7 +388,7 @@ add_camera() {
fi fi
if [ "$camopt" == generic ]; then if [ "$camopt" == generic ]; then
echo "Don't add cameras to the generic instance." echo "Don't add cameras to the template instance."
main_menu main_menu
fi fi
@@ -710,10 +711,10 @@ prepare () {
echo 'Updating config.yaml' echo 'Updating config.yaml'
sudo -u $user mkdir /home/$user/.octoprint sudo -u $user mkdir /home/$user/.octoprint
sudo -u $user cp -p $SCRIPTDIR/config.basic /home/$user/.octoprint/config.yaml sudo -u $user cp -p $SCRIPTDIR/config.basic /home/$user/.octoprint/config.yaml
#Add this is as an option #Haproxy
echo echo
echo echo
echo 'You now have the option of setting up haproxy.' echo 'You have the option of setting up haproxy.'
echo 'This binds instances to a name on port 80 instead of having to type the port.' echo 'This binds instances to a name on port 80 instead of having to type the port.'
echo echo
echo echo
@@ -817,7 +818,7 @@ prepare () {
firstrun() { firstrun() {
echo 'The template instance can be configured at this time.' echo 'The template instance can be configured at this time.'
echo 'This includes setting up the admin user and finishing the startup wizards.' echo 'This includes setting up the admin user and finishing the startup wizards.'
echo 'This avoids you having to connect to the template to set these up.' echo 'If you do these now, you will not have to connect to the template with a browser.'
if prompt_confirm "Do you want to setup your admin user now?"; then if prompt_confirm "Do you want to setup your admin user now?"; then
echo 'Enter admin user name (no spaces): ' echo 'Enter admin user name (no spaces): '
@@ -922,6 +923,37 @@ remove_everything() {
fi fi
} }
restart_all() {
get_settings
readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p')
for instance in "${instances[@]}"; do
if [ "$instance" == generic ]; then
continue
fi
echo "Trying to restart instance $instance"
systemctl restart $instance
done
exit 0
}
back_up() {
INSTANCE=$1
echo "Creating backup of $INSTANCE...."
sudo -p $user tar -cz $INSTANCE_$(date)_backup.tar.gz /home/$user/.$INSTANCE -C /home/$user
echo "Tarred and gzipped backup created in /home/$user"
}
back_up_all() {
get_settings
readarray -t instances < <(cat /etc/octoprint_instances | sed -n -e 's/^instance:\([[:alnum:]]*\) .*/\1/p')
for instance in "${instances[@]}"; do
if [ "$instance" == generic ]; then
continue
fi
back_up $instance
done
}
main_menu() { main_menu() {
#reset #reset
UDEV='' UDEV=''
@@ -971,8 +1003,16 @@ if [ $SUDO_USER ]; then user=$SUDO_USER; fi
logfile='octoprint_deploy.log' logfile='octoprint_deploy.log'
SCRIPTDIR=$(dirname $(readlink -f $0)) SCRIPTDIR=$(dirname $(readlink -f $0))
#command line arguments
if [ "$1" == remove ]; then if [ "$1" == remove ]; then
remove_everything remove_everything
fi fi
if [ "$1" == restart_all ]; then
restart_all
fi
if [ "$1" == backup ]; then
back_up_all
fi
main_menu main_menu