pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


Quantron backup script, 2nd generation
Posted by Anonymous on Fri 10th Jan 2020 10:03
raw | new post
view followups (newest first): Quantron backup script, 3rd generation by Anonymous

  1. #!/bin/bash
  2.  
  3. export PATH=/sbin:/usr/sbin:/bin:/usr/bin
  4.  
  5. printf '#\n'
  6. printf '# Quantron backup script STARTING...\n'
  7.  
  8. systemctl stop codesys3-rt.service
  9.  
  10. export TERM=linux
  11. exec 0<>/dev/tty0 1>&0 2>&0
  12. clear
  13.  
  14. printf '#\n'
  15. printf '# Welcome to the QUANTRON backup\n'
  16. printf '#\n'
  17.  
  18. is_usbstick_mounted()
  19. {
  20.         grep -q -E \
  21.                 '[[:space:]]+/media/usb0[[:space:]]+(fat|vfat|ntfs|ext4)[[:space:]]+(rw|ro),' \
  22.                 '/proc/self/mounts'
  23.         return $?
  24. }
  25.  
  26. do_menu()
  27. {
  28.         printf ' * Menu:\n'
  29.         printf ' - Press <ESC> key for abort\n' # key="A"
  30.         printf ' - Press <T> key for backup\n' # key="C"
  31.         printf ' - Press <L%%/R%%> key for restore\n' # key="D"
  32.  
  33.         key=""
  34.  
  35.         for ((;;)) ; do
  36.                 printf '0\n' >'/sys/devices/platform/imx21-fb.0/graphics/fb0/blank'
  37.                 IFS="" read -e -r -u0 -N1 key
  38.  
  39.                 case "$key" in
  40.                         A)
  41.                                 printf '# Aborting...\n'
  42.                                 exit 0
  43.                                 ;;
  44.                         C)
  45.                                 printf '# Starting backup...'
  46.                                 do_backup
  47.                                 exit 0
  48.                                 ;;
  49.                         D)
  50.                                 printf '# Starting restore...'
  51.                                 do_restore
  52.                                 exit 0
  53.                                 ;;
  54.                 esac
  55.         done
  56. }
  57.  
  58. do_backup()
  59. {
  60.         if ! is_usbstick_mounted ; then
  61.                 printf '# ERROR: No USB stick mounted, aborting\n'
  62.                 exit 1
  63.         fi
  64.  
  65.         if ! /sbin/eag_usbstick mount_writeable ; then
  66.                 printf '# ERROR: Cannot mount stick writeable, aborting\n'
  67.         fi
  68.  
  69.         mkdir -p /media/usb0/quantron_backup
  70.  
  71.         set -o pipefail
  72.         (( backuperr=0 ))
  73.  
  74.         (cd / ; tar -cvf - var/dyn/) | \
  75.                 bzip2 -9 | \
  76.                 tee \
  77.                         >(md5sum /dev/stdin | sed 's/\/dev\/stdin/quantron_var_dyn_backup.tar.bz2/' >/media/usb0/quantron_backup/quantron_var_dyn_backup.tar.bz2.md5sum) \
  78.                         >/media/usb0/quantron_backup/quantron_var_dyn_backup.tar.bz2
  79.         (( backuperr+=$? ))
  80.  
  81.         sync ; sync # UNIX tradition!
  82.         /sbin/eag_usbstick mount_readonly
  83.         (( backuperr+=$? ))
  84.  
  85.         if (( backuperr == 0 )) ; then
  86.                 printf '#\n# Backup success.\n#\n'
  87.         else
  88.                 printf '#\n# Backup FAILED!!\n#\n'
  89.         fi
  90.  
  91.         exit 0
  92. }
  93.  
  94. do_restore()
  95. {
  96.         true
  97. }
  98.  
  99. do_menu
  100.  
  101.  
  102.  
  103. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at